Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to call a command from another command with flags #92

Closed
santoshlite opened this issue Aug 10, 2023 · 0 comments
Closed

How to call a command from another command with flags #92

santoshlite opened this issue Aug 10, 2023 · 0 comments

Comments

@santoshlite
Copy link

Hey, I am trying to call a command with a specific flag from another command but I've been struggling to make it work. Here is what I am doing:

var startCmd = &cobra.Command{
	Use:   "start",
	Short: "The central command for the CLI.",
	Long: `start can execute any of the other commands in the CLI.`,
	Run: func(cmd *cobra.Command, args []string) {
		getCmd.SetArgs([]string{"--data", "price"})
		getCmd.Run(cmd, os.Args[1:])
               // getCmdRun(cmd, []string{"--data", "price"}) -> tried this as well but failed too
	},
}

func init() {
	rootCmd.AddCommand(startCmd)
	startCmd.AddCommand(getCmd)
}

Each time it raises a warning from the getCmd command saying my flag is not recognized. How do we do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant