-
Notifications
You must be signed in to change notification settings - Fork 70
/
options.go
73 lines (60 loc) · 2.37 KB
/
options.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2023, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cli
import "cogentcore.org/core/base/strcase"
// Options contains the options passed to cli
// that control its behavior.
type Options struct {
// AppName is the name of the cli app.
AppName string
// AppAbout is the description of the cli app.
AppAbout string
// Fatal is whether to, if there is an error in [Run],
// print it and fatally exit the program through [os.Exit]
// with an exit code of 1.
Fatal bool
// PrintSuccess is whether to print a message indicating
// that a command was successful after it is run, unless
// the user passes -q or -quiet to the command, in which
// case the success message will always not be printed.
PrintSuccess bool
// DefaultEncoding is the default encoding format for config files.
// currently toml is the only supported format, but others could be added
// if needed.
DefaultEncoding string
// DefaultFiles are the default configuration file paths
DefaultFiles []string
// IncludePaths is a list of file paths to try for finding config files
// specified in Include field or via the command line --config --cfg or -c args.
// Set this prior to calling Config; default is current directory '.' and 'configs'.
// The include paths are searched in reverse order such that first specified include
// paths get the highest precedence (config files found in earlier include paths
// override those found in later ones).
IncludePaths []string
// SearchUp indicates whether to search up the filesystem
// for the default config file by checking the provided default
// config file location relative to each directory up the tree
SearchUp bool
// NeedConfigFile indicates whether a configuration file
// must be provided for the command to run
NeedConfigFile bool
}
// DefaultOptions returns a new [Options] value
// with standard default values, based on the given
// app name and optional app about info.
func DefaultOptions(name string, about ...string) *Options {
abt := ""
if len(about) > 0 {
abt = about[0]
}
return &Options{
AppName: name,
AppAbout: abt,
Fatal: true,
PrintSuccess: true,
DefaultEncoding: "toml",
DefaultFiles: []string{strcase.ToKebab(name) + ".toml"},
IncludePaths: []string{".", "configs"},
}
}