| 56 | ) |
| 57 | |
| 58 | func 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)) |