我有以下命令+子命令:
aws.go
// s3Cmd represents the out command
var s3Cmd = &cobra.Command{
Use: "s3",
Short: "Uploads saved tarballs to an s3 bucket in aws",
Long: `Uploads files to S3 using the credentials passed as arguments
s3Bucket and the aws key and secret.`,
RunE: func(cmd *cobra.Command, args []string) error {
// some logic
},
}
func init() {
outCmd.AddCommand(s3Cmd)
}
out.go
// outCmd represents the out command
var outCmd = &cobra.Command{
Use: "out",
Short: "Consumes data out from RabbitMQ and stores to tarballs",
Long: `Select your output directory and batchsize of the tarballs.
When there are no more messages in the queue, press CTRL + c, to interrupt
the consumption and save the last message buffers.`,
RunE: func(cmd *cobra.Command, args []string) error {
//logic
},
}
func init() {
RootCmd.AddCommand(outCmd)
}
当我执行go run main.go out --args s3 --args
上面运行 s3Command 内部的逻辑,但不运行 outCmd 内部的内容,有没有办法先运行 outCommand 逻辑,然后先运行 s3Cmd?