// NewUnregisterCommand returns a command to allow the user to unregister a controller.
426836
func NewUnregisterCommand(store jujuclient.ClientStore) cmd.Command {
	if store == nil {
		panic("valid store must be specified")
	}
	cmd := &unregisterCommand{store: store}
	return modelcmd.WrapBase(cmd)
}
1309795
func NewDestroyCommand() cmd.Command {
	cmd := destroyCommand{}
	cmd.controllerCredentialAPIFunc = cmd.credentialAPIForControllerModel
	cmd.environsDestroy = environs.Destroy
	// Even though this command is all about destroying a controller we end up
	// needing environment endpoints so we can fall back to the client destroy
	// environment method. This shouldn't really matter in practice as the
	// user trying to take down the controller will need to have access to the
	// controller environment anyway.
	return modelcmd.WrapController(
		&cmd,
		modelcmd.WrapControllerSkipControllerFlags,
		modelcmd.WrapControllerSkipDefaultController,
	)
}
543678
func NewCommand() *cobra.Command {
	var (
		insecure               bool
		logLevel               string
		glogLevel              int
		clientConfig           clientcmd.ClientConfig
		staticAssetsDir        string
		baseHRef               string
		repoServerAddress      string
		dexServerAddress       string
		disableAuth            bool
		tlsConfigCustomizerSrc func() (tls.ConfigCustomizer, error)
		cacheSrc               func() (*cache.Cache, error)
	)
	var command = &cobra.Command{
		Use:   cliName,
		Short: "Run the argocd API server",
		Long:  "Run the argocd API server",
		Run: func(c *cobra.Command, args []string) {
			cli.SetLogLevel(logLevel)
			cli.SetGLogLevel(glogLevel)

			config, err := clientConfig.ClientConfig()
			errors.CheckError(err)
			config.QPS = common.K8sClientConfigQPS
			config.Burst = common.K8sClientConfigBurst

			namespace, _, err := clientConfig.Namespace()
			errors.CheckError(err)

			tlsConfigCustomizer, err := tlsConfigCustomizerSrc()
			errors.CheckError(err)
			cache, err := cacheSrc()
			errors.CheckError(err)

			kubeclientset := kubernetes.NewForConfigOrDie(config)
			appclientset := appclientset.NewForConfigOrDie(config)
			repoclientset := reposerver.NewRepoServerClientset(repoServerAddress, 0)

			argoCDOpts := server.ArgoCDServerOpts{
				Insecure:            insecure,
				Namespace:           namespace,
				StaticAssetsDir:     staticAssetsDir,
				BaseHRef:            baseHRef,
				KubeClientset:       kubeclientset,
				AppClientset:        appclientset,
				RepoClientset:       repoclientset,
				DexServerAddr:       dexServerAddress,
				DisableAuth:         disableAuth,
				TLSConfigCustomizer: tlsConfigCustomizer,
				Cache:               cache,
			}

			stats.RegisterStackDumper()
			stats.StartStatsTicker(10 * time.Minute)
			stats.RegisterHeapDumper("memprofile")

			for {
				ctx := context.Background()
				ctx, cancel := context.WithCancel(ctx)
				argocd := server.NewServer(ctx, argoCDOpts)
				argocd.Run(ctx, common.PortAPIServer)
				cancel()
			}
		},
	}

	clientConfig = cli.AddKubectlFlagsToCmd(command)
	command.Flags().BoolVar(&insecure, "insecure", false, "Run server without TLS")
	command.Flags().StringVar(&staticAssetsDir, "staticassets", "", "Static assets directory path")
	command.Flags().StringVar(&baseHRef, "basehref", "/", "Value for base href in index.html. Used if Argo CD is running behind reverse proxy under subpath different from /")
	command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error")
	command.Flags().IntVar(&glogLevel, "gloglevel", 0, "Set the glog logging level")
	command.Flags().StringVar(&repoServerAddress, "repo-server", common.DefaultRepoServerAddr, "Repo server address")
	command.Flags().StringVar(&dexServerAddress, "dex-server", common.DefaultDexServerAddr, "Dex server address")
	command.Flags().BoolVar(&disableAuth, "disable-auth", false, "Disable client authentication")
	command.AddCommand(cli.NewVersionCmd(cliName))
	tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(command)
	cacheSrc = cache.AddCacheFlagsToCmd(command)
	return command
}
660426
func NewCommand() *cobra.Command {
	var command = &cobra.Command{
		Use:   CLIName,
		Short: "argo is the command line interface to Argo",
		Run: func(cmd *cobra.Command, args []string) {
			cmd.HelpFunc()(cmd, args)
		},
	}

	command.AddCommand(NewCompletionCommand())
	command.AddCommand(NewDeleteCommand())
	command.AddCommand(NewGetCommand())
	command.AddCommand(NewLintCommand())
	command.AddCommand(NewListCommand())
	command.AddCommand(NewLogsCommand())
	command.AddCommand(NewResubmitCommand())
	command.AddCommand(NewResumeCommand())
	command.AddCommand(NewRetryCommand())
	command.AddCommand(NewSubmitCommand())
	command.AddCommand(NewSuspendCommand())
	command.AddCommand(NewWaitCommand())
	command.AddCommand(NewWatchCommand())
	command.AddCommand(NewTerminateCommand())
	command.AddCommand(cmd.NewVersionCmd(CLIName))

	addKubectlFlagsToCmd(command)
	return command
}
567626
func NewPoolRemoveCommand() cmd.Command {
	cmd := &poolRemoveCommand{}
	cmd.newAPIFunc = func() (PoolRemoveAPI, error) {
		return cmd.NewStorageAPI()
	}
	return modelcmd.Wrap(cmd)
}
719993
func NewRepoAddCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
	var (
		repo                  appsv1.Repository
		upsert                bool
		sshPrivateKeyPath     string
		insecureIgnoreHostKey bool
	)
	var command = &cobra.Command{
		Use:   "add REPO",
		Short: "Add git repository credentials",
		Run: func(c *cobra.Command, args []string) {
			if len(args) != 1 {
				c.HelpFunc()(c, args)
				os.Exit(1)
			}
			repo.Repo = args[0]
			if sshPrivateKeyPath != "" {
				keyData, err := ioutil.ReadFile(sshPrivateKeyPath)
				if err != nil {
					log.Fatal(err)
				}
				repo.SSHPrivateKey = string(keyData)
			}
			repo.InsecureIgnoreHostKey = insecureIgnoreHostKey
			// First test the repo *without* username/password. This gives us a hint on whether this
			// is a private repo.
			// NOTE: it is important not to run git commands to test git credentials on the user's
			// system since it may mess with their git credential store (e.g. osx keychain).
			// See issue #315
			err := git.TestRepo(repo.Repo, "", "", repo.SSHPrivateKey, repo.InsecureIgnoreHostKey)
			if err != nil {
				if git.IsSSHURL(repo.Repo) {
					// If we failed using git SSH credentials, then the repo is automatically bad
					log.Fatal(err)
				}
				// If we can't test the repo, it's probably private. Prompt for credentials and
				// let the server test it.
				repo.Username, repo.Password = cli.PromptCredentials(repo.Username, repo.Password)
			}
			conn, repoIf := argocdclient.NewClientOrDie(clientOpts).NewRepoClientOrDie()
			defer util.Close(conn)
			repoCreateReq := repository.RepoCreateRequest{
				Repo:   &repo,
				Upsert: upsert,
			}
			createdRepo, err := repoIf.Create(context.Background(), &repoCreateReq)
			errors.CheckError(err)
			fmt.Printf("repository '%s' added\n", createdRepo.Repo)
		},
	}
	command.Flags().StringVar(&repo.Username, "username", "", "username to the repository")
	command.Flags().StringVar(&repo.Password, "password", "", "password to the repository")
	command.Flags().StringVar(&sshPrivateKeyPath, "ssh-private-key-path", "", "path to the private ssh key (e.g. ~/.ssh/id_rsa)")
	command.Flags().BoolVar(&insecureIgnoreHostKey, "insecure-ignore-host-key", false, "disables SSH strict host key checking")
	command.Flags().BoolVar(&upsert, "upsert", false, "Override an existing repository with the same name even if the spec differs")
	return command
}
982876
func NewUploadCommand(deps UploadDeps) modelcmd.ModelCommand {
	return modelcmd.Wrap(&UploadCommand{deps: deps})
}
250228
func NewCommand(module Module, usedModules ...Module) *cli.Command {
	flags := []cli.Flag{}
	flags = append(flags, module.Flags...)
	flags = append(flags, module.Depend.Flags(usedModules...)...)

	beforeActions := Actions{}
	beforeActions.Add(module.Depend.BeforeActions()...)
	beforeActions.Add(module.Before)
	actions := Actions{}
	actions.Add(module.Depend.Actions()...)
	actions.Add(module.Action)
	afterActions := Actions{}
	afterActions.Add(module.After)
	afterActions.Add(module.Depend.AfterActions()...)

	return &cli.Command{
		Name:   module.Name,
		Usage:  module.Usage,
		Flags:  flags,
		Before: cli.BeforeFunc(beforeActions.Wrap()),
		Action: actions.Wrap(),
		After:  cli.AfterFunc(afterActions.Wrap()),
	}
}
1271852
func NewApplicationDeleteCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
	var (
		cascade bool
	)
	var command = &cobra.Command{
		Use:   "delete APPNAME",
		Short: "Delete an application",
		Run: func(c *cobra.Command, args []string) {
			if len(args) == 0 {
				c.HelpFunc()(c, args)
				os.Exit(1)
			}
			conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
			defer util.Close(conn)
			for _, appName := range args {
				appDeleteReq := application.ApplicationDeleteRequest{
					Name: &appName,
				}
				if c.Flag("cascade").Changed {
					appDeleteReq.Cascade = &cascade
				}
				_, err := appIf.Delete(context.Background(), &appDeleteReq)
				errors.CheckError(err)
			}
		},
	}
	command.Flags().BoolVar(&cascade, "cascade", true, "Perform a cascaded deletion of all application resources")
	return command
}
816139
func NewLoginCommand() cmd.Command {
	var c loginCommand
	c.SetClientStore(loginClientStore)
	c.CanClearCurrentModel = true
	return modelcmd.WrapController(&c, modelcmd.WrapControllerSkipControllerFlags)
}
132802
func NewRegistry(name string, r func(...registry.Option) registry.Registry) Option {
	return func(o *Options) {
		o.Registries[name] = r
	}
}
656340
func NewListCommand() cmd.Command {
	return modelcmd.Wrap(&listCommand{
		apiFunc: func(c newAPIRoot) (blockListAPI, error) {
			return getBlockAPI(c)
		},
		controllerAPIFunc: func(c newControllerAPIRoot) (controllerListAPI, error) {
			return getControllerAPI(c)
		},
	})
}
574943
func (r *PrefixedRegistry) Unregister(name string) {
	realName := r.prefix + name
	r.underlying.Unregister(realName)
}
893652
func (cmd *Command) RegisterFunc(name string, fn CommandFunc, argvFn ArgvFunc) *Command {
	return cmd.Register(&Command{Name: name, Fn: fn, Argv: argvFn})
}
1040276
func NewCommand(name, shortDescription string, action actionFunc) *Command {
	cmd := &Command{
		Name:             name,
		ShortDescription: shortDescription,
		Action:           action,
	}

	return cmd
}
897653
func NewOfferCommand() cmd.Command {
	offerCmd := &offerCommand{}
	offerCmd.newAPIFunc = func() (OfferAPI, error) {
		return offerCmd.NewApplicationOffersAPI()
	}
	offerCmd.refreshModels = offerCmd.ControllerCommandBase.RefreshModels
	return modelcmd.WrapController(offerCmd)
}
824366
func registerCommand(command *cmd.Command) {
	setCommandDefaults(command)
	commands[command.Name] = command
}