-
Notifications
You must be signed in to change notification settings - Fork 4
/
nop.go
55 lines (44 loc) · 1.06 KB
/
nop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright © 2019-2020 Platina Systems, Inc. All rights reserved.
// Use of this source code is governed by the GPL-2 license described in the
// LICENSE file.
package nop
import (
"errors"
"fmt"
"github.com/platinasystems/goes/cmd"
"github.com/platinasystems/goes/external/flags"
"github.com/platinasystems/goes/lang"
)
var ErrorForced = errors.New("Forced error")
type Command struct {
C string
}
func (c Command) String() string {
if c.C == "" {
return "nop"
}
return c.C
}
func (c Command) Usage() string { return c.String() + " ..." }
func (c Command) Apropos() lang.Alt {
return lang.Alt{
lang.EnUS: "do nothing",
}
}
func (c Command) Man() lang.Alt {
return lang.Alt{
lang.EnUS: `
DESCRIPTION
The ` + c.String() + ` command does nothing. It is intended for use in
scripts.`,
}
}
func (Command) Kind() cmd.Kind { return cmd.DontFork }
func (c Command) Main(args ...string) (err error) {
opt := "--force-error"
flag, args := flags.New(args, opt)
if flag.ByName[opt] {
err = fmt.Errorf("%s: %w(%s)", c.String(), ErrorForced, opt)
}
return
}