-
Notifications
You must be signed in to change notification settings - Fork 4
/
manager.cobra.go
49 lines (37 loc) · 1.8 KB
/
manager.cobra.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
package config
import (
"bunnyshell.com/cli/pkg/util"
"github.com/spf13/cobra"
)
type ShellCompletion func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
func (manager *Manager) CommandWithGlobalOptions(command *cobra.Command) {
flags := command.PersistentFlags()
configFileFlag := manager.options.ConfigFile.GetMainFlag()
flags.AddFlag(configFileFlag)
_ = flags.SetAnnotation(configFileFlag.Name, cobra.BashCompFilenameExt, []string{"yaml", "json"})
flags.AddFlag(manager.options.Debug.GetMainFlag())
flags.AddFlag(manager.options.NoProgress.GetMainFlag())
flags.AddFlag(manager.options.NonInteractive.GetMainFlag())
flags.AddFlag(manager.options.Verbosity.GetMainFlag())
profileFlag := manager.options.ProfileName.GetMainFlag()
flags.AddFlag(profileFlag)
_ = command.RegisterFlagCompletionFunc(profileFlag.Name, manager.profileNamesCompletion())
outputFormatFlag := manager.options.OutputFormat.GetMainFlag()
flags.AddFlag(outputFormatFlag)
_ = command.RegisterFlagCompletionFunc(outputFormatFlag.Name, manager.outputTypesCompletion())
}
func (manager *Manager) CommandWithAPI(command *cobra.Command) {
flags := command.PersistentFlags()
flags.AddFlag(manager.options.Token.GetFlag("token", util.FlagRequired, util.FlagHidden))
flags.AddFlag(manager.options.Host.GetMainFlag())
flags.AddFlag(manager.options.Timeout.GetMainFlag())
}
func (manager *Manager) profileNamesCompletion() ShellCompletion {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
MainManager.Load()
return MainManager.config.profileNames(), cobra.ShellCompDirectiveNoFileComp
}
}
func (manager *Manager) outputTypesCompletion() ShellCompletion {
return cobra.FixedCompletions(FormatDescriptions, cobra.ShellCompDirectiveDefault)
}