-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeclarations.go
More file actions
58 lines (50 loc) · 2.01 KB
/
declarations.go
File metadata and controls
58 lines (50 loc) · 2.01 KB
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
// Copyright (c) Christoph Berger. All rights reserved.
// Use of this source code is governed by the BSD (3-Clause)
// License that can be found in the LICENSE.txt file.
//
// This source code may import third-party source code whose
// licenses are provided in the respective license files.
package start
import (
"github.com/laurent22/toml-go"
)
//// Command Declarations
// CommandMap represents a list of Command objects.
type CommandMap map[string]*Command // TODO: Make struct with Usage command
// PrivateFlagMap collects the flag names that commands claim
// for themselves.
// Purpose: Enable Usage() and readCommand() to quickly check which
// flags are command-specific and which ones are global flags.
type privateFlagsMap map[string]bool
// Command defines a command or a subcommand.
// Flags is a list of flag names that the command accepts.
// If a flag is passed to the command that the command does not accept,
// and if that flag is not among the global flags available for all commands,
// then Up() returns an error. If Flags is empty, all global flags are allowed.
// ShortHelp contains a short help string that is used in --help.
// LongHelp contains a usage description that is used in --help <command>.
// Cmd contains the function to execute. It receives the list of
// arguments (without the flags, which are parsed already).
// For commands with child commands, Cmd can be left empty.
// Args gets filled with all arguments, excluding flags.
// Path is an optional path to external executables that reside outside
// $PATH. To be used with the External() function.
type Command struct {
Name string
Parent string
Flags []string
Short string
Long string
Cmd func(cmd *Command) error
Args []string
Path string
children CommandMap
}
//// Configuration File Declarations
// ConfigFile represents a configuration file.
// If the application has no configuration file, then doc is an empty
// toml.Document and path is empty.
type configFile struct {
doc toml.Document
path string
}