@@ -17,45 +17,33 @@ import (
1717 "github.com/bufdev/ibctl/cmd/ibctl/internal/ibctlcmd"
1818 "github.com/bufdev/ibctl/internal/ibctl/ibctlconfig"
1919 "github.com/bufdev/ibctl/internal/ibctl/ibctlpath"
20- "github.com/spf13/pflag"
2120)
2221
2322// NewCommand returns a new config edit command that opens the configuration file in an editor.
2423func NewCommand (name string , builder appext.SubCommandBuilder ) * appcmd.Command {
25- flags := newFlags ()
2624 return & appcmd.Command {
2725 Use : name ,
2826 Short : "Edit the configuration file in $EDITOR" ,
2927 Args : appcmd .NoArgs ,
3028 Run : builder .NewRunFunc (
3129 func (ctx context.Context , container appext.Container ) error {
32- return run (ctx , container , flags )
30+ return run (ctx , container )
3331 },
3432 ),
35- BindFlags : flags .Bind ,
3633 }
3734}
3835
39- type flags struct {
40- // Dir is the ibctl directory containing ibctl.yaml.
41- Dir string
42- }
43-
44- func newFlags () * flags {
45- return & flags {}
46- }
47-
48- // Bind registers the flag definitions with the given flag set.
49- func (f * flags ) Bind (flagSet * pflag.FlagSet ) {
50- flagSet .StringVar (& f .Dir , ibctlcmd .DirFlagName , "." , "The ibctl directory containing ibctl.yaml" )
51- }
52-
53- func run (ctx context.Context , container appext.Container , flags * flags ) error {
36+ func run (ctx context.Context , container appext.Container ) error {
37+ // Resolve the ibctl directory from the IBKR_DIR environment variable.
38+ dirPath , err := ibctlcmd .DirPath (container )
39+ if err != nil {
40+ return err
41+ }
5442 // Resolve the config file path from the base directory.
55- configFilePath := ibctlpath .ConfigFilePath (flags . Dir )
43+ configFilePath := ibctlpath .ConfigFilePath (dirPath )
5644 // Create the configuration file with the default template if it does not exist.
5745 if _ , err := os .Stat (configFilePath ); os .IsNotExist (err ) {
58- if err := ibctlconfig .InitConfig (flags . Dir ); err != nil {
46+ if err := ibctlconfig .InitConfig (dirPath ); err != nil {
5947 return err
6048 }
6149 }
@@ -73,6 +61,6 @@ func run(ctx context.Context, container appext.Container, flags *flags) error {
7361 return fmt .Errorf ("running editor: %w" , err )
7462 }
7563 // Print the path of the edited file.
76- _ , err : = fmt .Fprintf (container .Stdout (), "%s\n " , configFilePath )
64+ _ , err = fmt .Fprintf (container .Stdout (), "%s\n " , configFilePath )
7765 return err
7866}
0 commit comments