MCPcopy Create free account
hub / github.com/algolia/cli / NewRootCmd

Function NewRootCmd

pkg/cmd/root/root.go:58–123  ·  view source on GitHub ↗
(f *cmdutil.Factory)

Source from the content-addressed store, hash-verified

56)
57
58func NewRootCmd(f *cmdutil.Factory) *cobra.Command {
59 cmd := &cobra.Command{
60 Use: "algolia <command> <subcommand> [flags]",
61 Version: version.Version,
62 Short: "Algolia CLI",
63 Long: "The official command-line tool to interact with Algolia.",
64
65 SilenceUsage: true,
66 SilenceErrors: true,
67 Example: heredoc.Doc(`
68 $ algolia search MOVIES --query "toy story"
69 $ algolia objects browse MOVIES
70 $ algolia apikeys create --acl search
71 $ algolia rules import MOVIES -f rules.json
72 `),
73 }
74
75 cmd.SetOut(f.IOStreams.Out)
76 cmd.SetErr(f.IOStreams.ErrOut)
77
78 cmd.SetVersionTemplate(version.Template)
79 cmd.SetUsageFunc(rootUsageFunc(f.IOStreams, cmd))
80 cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
81 rootHelpFunc(f, cmd, args)
82 })
83 cmd.SetFlagErrorFunc(rootFlagErrorFunc)
84
85 cmd.PersistentFlags().
86 StringVarP(&f.Config.Profile().Name, "profile", "p", "", "The profile to use")
87 _ = cmd.RegisterFlagCompletionFunc("profile", cmdutil.ConfiguredProfilesCompletionFunc(f))
88
89 cmd.PersistentFlags().
90 StringVarP(&f.Config.Profile().ApplicationID, "application-id", "", "", "The application ID")
91 cmd.PersistentFlags().StringVarP(&f.Config.Profile().APIKey, "api-key", "", "", "The API key")
92 cmd.PersistentFlags().
93 StringVarP(&f.Config.Profile().AdminAPIKey, "admin-api-key", "", "", "The admin API key")
94 _ = cmd.PersistentFlags().MarkDeprecated("admin-api-key", "use --api-key instead")
95 cmd.PersistentFlags().
96 StringSliceVar(&f.Config.Profile().SearchHosts, "search-hosts", nil, "The list of search hosts as CSV")
97
98 cmd.Flags().BoolP("version", "v", false, "Get the version of the Algolia CLI")
99
100 // CLI related commands
101 cmd.AddCommand(authcmd.NewAuthCmd(f))
102 cmd.AddCommand(profile.NewProfileCmd(f))
103 cmd.AddCommand(describe.NewDescribeCmd(f))
104
105 // Convenience commands
106 cmd.AddCommand(open.NewOpenCmd(f))
107
108 // API related commands
109 cmd.AddCommand(application.NewApplicationCmd(f))
110 cmd.AddCommand(search.NewSearchCmd(f))
111 cmd.AddCommand(indices.NewIndicesCmd(f))
112 cmd.AddCommand(objects.NewObjectsCmd(f))
113 cmd.AddCommand(apikeys.NewAPIKeysCmd(f))
114 cmd.AddCommand(settings.NewSettingsCmd(f))
115 cmd.AddCommand(rules.NewRulesCmd(f))

Callers 5

TestDescribeCommandFunction · 0.92
TestSchemaAliasFunction · 0.92
runFunction · 0.92
ExecuteFunction · 0.85

Calls 15

NewProfileCmdFunction · 0.92
NewDescribeCmdFunction · 0.92
NewOpenCmdFunction · 0.92
NewApplicationCmdFunction · 0.92
NewSearchCmdFunction · 0.92
NewIndicesCmdFunction · 0.92
NewObjectsCmdFunction · 0.92
NewAPIKeysCmdFunction · 0.92
NewSettingsCmdFunction · 0.92
NewRulesCmdFunction · 0.92
NewSynonymsCmdFunction · 0.92

Tested by 3

TestDescribeCommandFunction · 0.74
TestSchemaAliasFunction · 0.74