Skip to content

Commit 8dc0bcb

Browse files
committed
commit
1 parent a8f2302 commit 8dc0bcb

11 files changed

Lines changed: 242 additions & 243 deletions

File tree

cmd/ibctl/internal/command/config/configedit/configedit.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"buf.build/go/app/appext"
1717
"github.com/bufdev/ibctl/cmd/ibctl/internal/ibctlcmd"
1818
"github.com/bufdev/ibctl/internal/ibctl/ibctlconfig"
19+
"github.com/bufdev/ibctl/internal/ibctl/ibctlpath"
1920
"github.com/spf13/pflag"
2021
)
2122

@@ -36,8 +37,8 @@ func NewCommand(name string, builder appext.SubCommandBuilder) *appcmd.Command {
3637
}
3738

3839
type flags struct {
39-
// Config is the path to the configuration file.
40-
Config string
40+
// Dir is the ibctl directory containing ibctl.yaml.
41+
Dir string
4142
}
4243

4344
func newFlags() *flags {
@@ -46,13 +47,15 @@ func newFlags() *flags {
4647

4748
// Bind registers the flag definitions with the given flag set.
4849
func (f *flags) Bind(flagSet *pflag.FlagSet) {
49-
flagSet.StringVar(&f.Config, ibctlcmd.ConfigFlagName, ibctlconfig.DefaultConfigFileName, "The configuration file path")
50+
flagSet.StringVar(&f.Dir, ibctlcmd.DirFlagName, ".", "The ibctl directory containing ibctl.yaml")
5051
}
5152

5253
func run(ctx context.Context, container appext.Container, flags *flags) error {
54+
// Resolve the config file path from the base directory.
55+
configFilePath := ibctlpath.ConfigFilePath(flags.Dir)
5356
// Create the configuration file with the default template if it does not exist.
54-
if _, err := os.Stat(flags.Config); os.IsNotExist(err) {
55-
if err := ibctlconfig.InitConfig(flags.Config); err != nil {
57+
if _, err := os.Stat(configFilePath); os.IsNotExist(err) {
58+
if err := ibctlconfig.InitConfig(flags.Dir); err != nil {
5659
return err
5760
}
5861
}
@@ -62,14 +65,14 @@ func run(ctx context.Context, container appext.Container, flags *flags) error {
6265
return errors.New("EDITOR environment variable is not set")
6366
}
6467
// Open the configuration file in the editor.
65-
cmd := exec.CommandContext(ctx, editor, flags.Config)
68+
cmd := exec.CommandContext(ctx, editor, configFilePath)
6669
cmd.Stdin = os.Stdin
6770
cmd.Stdout = os.Stdout
6871
cmd.Stderr = os.Stderr
6972
if err := cmd.Run(); err != nil {
7073
return fmt.Errorf("running editor: %w", err)
7174
}
7275
// Print the path of the edited file.
73-
_, err := fmt.Fprintf(container.Stdout(), "%s\n", flags.Config)
76+
_, err := fmt.Fprintf(container.Stdout(), "%s\n", configFilePath)
7477
return err
7578
}

cmd/ibctl/internal/command/config/configinit/configinit.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func NewCommand(name string, builder appext.SubCommandBuilder) *appcmd.Command {
3333
}
3434

3535
type flags struct {
36-
// Config is the path to the configuration file.
37-
Config string
36+
// Dir is the ibctl directory containing ibctl.yaml.
37+
Dir string
3838
}
3939

4040
func newFlags() *flags {
@@ -43,15 +43,15 @@ func newFlags() *flags {
4343

4444
// Bind registers the flag definitions with the given flag set.
4545
func (f *flags) Bind(flagSet *pflag.FlagSet) {
46-
flagSet.StringVar(&f.Config, ibctlcmd.ConfigFlagName, ibctlconfig.DefaultConfigFileName, "The configuration file path")
46+
flagSet.StringVar(&f.Dir, ibctlcmd.DirFlagName, ".", "The ibctl directory containing ibctl.yaml")
4747
}
4848

4949
func run(_ context.Context, container appext.Container, flags *flags) error {
50-
// Create the configuration file at the specified path.
51-
if err := ibctlconfig.InitConfig(flags.Config); err != nil {
50+
// Create the configuration file in the specified directory.
51+
if err := ibctlconfig.InitConfig(flags.Dir); err != nil {
5252
return err
5353
}
54-
// Print the path of the created file so the user knows where to find it.
55-
_, err := fmt.Fprintf(container.Stdout(), "%s\n", flags.Config)
54+
// Print the directory path so the user knows where to find it.
55+
_, err := fmt.Fprintf(container.Stdout(), "%s\n", flags.Dir)
5656
return err
5757
}

cmd/ibctl/internal/command/config/configvalidate/configvalidate.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func NewCommand(name string, builder appext.SubCommandBuilder) *appcmd.Command {
3232
}
3333

3434
type flags struct {
35-
// Config is the path to the configuration file.
36-
Config string
35+
// Dir is the ibctl directory containing ibctl.yaml.
36+
Dir string
3737
}
3838

3939
func newFlags() *flags {
@@ -42,9 +42,9 @@ func newFlags() *flags {
4242

4343
// Bind registers the flag definitions with the given flag set.
4444
func (f *flags) Bind(flagSet *pflag.FlagSet) {
45-
flagSet.StringVar(&f.Config, ibctlcmd.ConfigFlagName, ibctlconfig.DefaultConfigFileName, "The configuration file path")
45+
flagSet.StringVar(&f.Dir, ibctlcmd.DirFlagName, ".", "The ibctl directory containing ibctl.yaml")
4646
}
4747

4848
func run(_ context.Context, _ appext.Container, flags *flags) error {
49-
return ibctlconfig.ValidateConfig(flags.Config)
49+
return ibctlconfig.ValidateConfig(flags.Dir)
5050
}

cmd/ibctl/internal/command/download/download.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"buf.build/go/app/appcmd"
1212
"buf.build/go/app/appext"
1313
"github.com/bufdev/ibctl/cmd/ibctl/internal/ibctlcmd"
14-
"github.com/bufdev/ibctl/internal/ibctl/ibctlconfig"
1514
"github.com/spf13/pflag"
1615
)
1716

@@ -32,8 +31,8 @@ func NewCommand(name string, builder appext.SubCommandBuilder) *appcmd.Command {
3231
}
3332

3433
type flags struct {
35-
// Config is the path to the configuration file.
36-
Config string
34+
// Dir is the ibctl directory containing ibctl.yaml.
35+
Dir string
3736
}
3837

3938
func newFlags() *flags {
@@ -42,12 +41,12 @@ func newFlags() *flags {
4241

4342
// Bind registers the flag definitions with the given flag set.
4443
func (f *flags) Bind(flagSet *pflag.FlagSet) {
45-
flagSet.StringVar(&f.Config, ibctlcmd.ConfigFlagName, ibctlconfig.DefaultConfigFileName, "The configuration file path")
44+
flagSet.StringVar(&f.Dir, ibctlcmd.DirFlagName, ".", "The ibctl directory containing ibctl.yaml")
4645
}
4746

4847
func run(ctx context.Context, container appext.Container, flags *flags) error {
4948
// Construct the downloader using shared command wiring.
50-
downloader, err := ibctlcmd.NewDownloader(container, flags.Config)
49+
downloader, err := ibctlcmd.NewDownloader(container, flags.Dir)
5150
if err != nil {
5251
return err
5352
}

cmd/ibctl/internal/command/holdings/holdingsoverview/holdingsoverview.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import (
2626
// formatFlagName is the flag name for the output format.
2727
const formatFlagName = "format"
2828

29+
// cachedFlagName is the flag name for skipping download and using cached data only.
30+
const cachedFlagName = "cached"
31+
2932
// NewCommand returns a new holdings overview command.
3033
func NewCommand(name string, builder appext.SubCommandBuilder) *appcmd.Command {
3134
flags := newFlags()
@@ -42,12 +45,9 @@ func NewCommand(name string, builder appext.SubCommandBuilder) *appcmd.Command {
4245
}
4346
}
4447

45-
// cachedFlagName is the flag name for skipping download and using cached data only.
46-
const cachedFlagName = "cached"
47-
4848
type flags struct {
49-
// Config is the path to the configuration file.
50-
Config string
49+
// Dir is the base directory containing ibctl.yaml and data subdirectories.
50+
Dir string
5151
// Format is the output format (table, csv, json).
5252
Format string
5353
// Cached skips downloading and uses only cached data.
@@ -60,7 +60,7 @@ func newFlags() *flags {
6060

6161
// Bind registers the flag definitions with the given flag set.
6262
func (f *flags) Bind(flagSet *pflag.FlagSet) {
63-
flagSet.StringVar(&f.Config, ibctlcmd.ConfigFlagName, ibctlconfig.DefaultConfigFileName, "The configuration file path")
63+
flagSet.StringVar(&f.Dir, ibctlcmd.DirFlagName, ".", "The ibctl directory containing ibctl.yaml")
6464
flagSet.StringVar(&f.Format, formatFlagName, "table", "Output format (table, csv, json)")
6565
flagSet.BoolVar(&f.Cached, cachedFlagName, false, "Skip downloading and use only cached data")
6666
}
@@ -70,14 +70,14 @@ func run(ctx context.Context, container appext.Container, flags *flags) error {
7070
if err != nil {
7171
return appcmd.NewInvalidArgumentError(err.Error())
7272
}
73-
// Read and validate the configuration file.
74-
config, err := ibctlconfig.ReadConfig(flags.Config)
73+
// Read and validate the configuration file from the base directory.
74+
config, err := ibctlconfig.ReadConfig(flags.Dir)
7575
if err != nil {
7676
return err
7777
}
7878
// Download fresh data unless --cached is set.
7979
if !flags.Cached {
80-
downloader, err := ibctlcmd.NewDownloader(container, flags.Config)
80+
downloader, err := ibctlcmd.NewDownloader(container, flags.Dir)
8181
if err != nil {
8282
return err
8383
}
@@ -86,19 +86,19 @@ func run(ctx context.Context, container appext.Container, flags *flags) error {
8686
}
8787
}
8888
// Merge seed lots + Activity Statement CSVs + Flex Query cached data across all accounts.
89-
// Trades come from data_dir (persistent), snapshots from cache_dir (blow-away safe).
89+
// Trades come from data/ (persistent), snapshots from cache/ (blow-away safe).
9090
mergedData, err := ibctlmerge.Merge(
91-
ibctlpath.DataAccountsDirPath(config.DataDirPath),
92-
ibctlpath.CacheAccountsDirPath(config.CacheDirPath),
93-
config.ActivityStatementsDirPath,
94-
config.SeedDirPath,
91+
ibctlpath.DataAccountsDirPath(config.DirPath),
92+
ibctlpath.CacheAccountsDirPath(config.DirPath),
93+
ibctlpath.ActivityStatementsDirPath(config.DirPath),
94+
ibctlpath.SeedDirPath(config.DirPath),
9595
config.AccountAliases,
9696
)
9797
if err != nil {
9898
return err
9999
}
100100
// Load FX rates for USD price conversion. Returns an empty store if no data available.
101-
fxStore := ibctlfxrates.NewStore(ibctlpath.CacheFXDirPath(config.CacheDirPath))
101+
fxStore := ibctlfxrates.NewStore(ibctlpath.CacheFXDirPath(config.DirPath))
102102
// Compute holdings via FIFO from all trade data, verified against IBKR positions.
103103
result, err := ibctlholdings.GetHoldingsOverview(mergedData.Trades, mergedData.Positions, mergedData.CashPositions, config, fxStore)
104104
if err != nil {

cmd/ibctl/internal/command/probe/probe.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ With --from/--to (YYYYMMDD format), overrides the period to test specific date r
5151
}
5252

5353
type flags struct {
54-
// Config is the path to the configuration file.
55-
Config string
54+
// Dir is the ibctl directory containing ibctl.yaml.
55+
Dir string
5656
// From is the start date (YYYYMMDD).
5757
From string
5858
// To is the end date (YYYYMMDD).
@@ -65,7 +65,7 @@ func newFlags() *flags {
6565

6666
// Bind registers the flag definitions with the given flag set.
6767
func (f *flags) Bind(flagSet *pflag.FlagSet) {
68-
flagSet.StringVar(&f.Config, ibctlcmd.ConfigFlagName, ibctlconfig.DefaultConfigFileName, "The configuration file path")
68+
flagSet.StringVar(&f.Dir, ibctlcmd.DirFlagName, ".", "The ibctl directory containing ibctl.yaml")
6969
flagSet.StringVar(&f.From, fromFlagName, "", "Start date (YYYYMMDD)")
7070
flagSet.StringVar(&f.To, toFlagName, "", "End date (YYYYMMDD)")
7171
}
@@ -89,7 +89,7 @@ func run(ctx context.Context, container appext.Container, flags *flags) error {
8989
}
9090
}
9191
// Read config for the query ID.
92-
config, err := ibctlconfig.ReadConfig(flags.Config)
92+
config, err := ibctlconfig.ReadConfig(flags.Dir)
9393
if err != nil {
9494
return err
9595
}

cmd/ibctl/internal/ibctlcmd/ibctlcmd.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ import (
1717
)
1818

1919
const (
20-
// ConfigFlagName is the flag name for the configuration file path.
21-
ConfigFlagName = "config"
20+
// DirFlagName is the flag name for the base directory path.
21+
DirFlagName = "dir"
2222
// ibkrFlexWebServiceTokenEnvVar is the environment variable name for the IBKR Flex Web Service token.
2323
ibkrFlexWebServiceTokenEnvVar = "IBKR_FLEX_WEB_SERVICE_TOKEN"
2424
)
2525

26-
// NewDownloader constructs a Downloader by reading the config file, extracting the
27-
// IBKR token from the environment, and creating the required API clients.
28-
func NewDownloader(container appext.Container, configFilePath string) (ibctldownload.Downloader, error) {
29-
// Read and validate the configuration file.
30-
config, err := ibctlconfig.ReadConfig(configFilePath)
26+
// NewDownloader constructs a Downloader by reading the config from the base directory,
27+
// extracting the IBKR token from the environment, and creating the required API clients.
28+
func NewDownloader(container appext.Container, dirPath string) (ibctldownload.Downloader, error) {
29+
// Read and validate the configuration file from the base directory.
30+
config, err := ibctlconfig.ReadConfig(dirPath)
3131
if err != nil {
3232
return nil, err
3333
}

0 commit comments

Comments
 (0)