func (opt *hogehogeOptions) Run(ctx context.Context, w io.Writer) error { //ここに必要な処理を書く return nil } func HogeCommand(ctx context.Context) *cobra.Command { opt := &hogehogeOptions {} cmd := &cobra.Command{ Use: “hoge”, Short: “ 処理の説明“, Run: func(cmd *cobra.Command, args [] string) { if err := opt.Run(ctx, cmd.OutOrStdout()); err != nil { panic(err) } }, } cmd.Flags().BoolVarP(&opt.Notice, “notice”, “”, opt.Notice, “notice”) cmd.Flags().BoolVarP(&opt.Dryrun, “dryrun”, “”, opt.Dryrun, “dryrun”) return cmd