diff --git a/cmd/checkout.go b/cmd/checkout.go index 5730239..ff2ed7f 100644 --- a/cmd/checkout.go +++ b/cmd/checkout.go @@ -30,13 +30,13 @@ import ( ) var checkoutCmd = &cobra.Command{ - Use: "checkout {refspec}", + Use: "checkout {refspec}", Aliases: []string{"ch"}, - Short: "Resets the index to show the balances at a particular transaction.", - Args: cobra.ExactArgs(1), + Short: "Resets the index to show the balances at a particular transaction.", + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { var err error - ctx, cancel := context.WithTimeout(context.Background(), 10 * time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() var root string @@ -66,9 +66,8 @@ var checkoutCmd = &cobra.Command{ } } - var target envelopes.Transaction - err = repo.Load(ctx, targetID, &target) + err = repo.LoadTransaction(ctx, targetID, &target) if err != nil { logrus.Fatal(err) } @@ -87,4 +86,4 @@ var checkoutCmd = &cobra.Command{ func init() { rootCmd.AddCommand(checkoutCmd) -} \ No newline at end of file +} diff --git a/cmd/commit.go b/cmd/commit.go index b1ca4c4..1b47177 100644 --- a/cmd/commit.go +++ b/cmd/commit.go @@ -66,10 +66,10 @@ const ( ) const ( - actualTimeFlag = "actual-time" + actualTimeFlag = "actual-time" actualTimeShorthand = "t" - actualTimeDefault = "" - actualTimeUsage = "The time and date when this transaction occurred." + actualTimeDefault = "" + actualTimeUsage = "The time and date when this transaction occurred." ) const ( @@ -82,8 +82,8 @@ const ( const ( bankRecordIDFlag = "bank-record-id" bankRecordIDShorthand = "b" - bankRecordIDDefault = "" - bankRecordIDUsage = "A unique ID assigned to this transaction by a financial institution." + bankRecordIDDefault = "" + bankRecordIDUsage = "A unique ID assigned to this transaction by a financial institution." ) var commitConfig = viper.New() @@ -196,8 +196,8 @@ var commitCmd = &cobra.Command{ Accounts: accounts, Budget: budget, }, - ActualTime: commitConfig.GetTime(actualTimeFlag), - PostedTime: commitConfig.GetTime(postedTimeFlag), + ActualTime: commitConfig.GetTime(actualTimeFlag), + PostedTime: commitConfig.GetTime(postedTimeFlag), EnteredTime: time.Now(), } if parent.Equal(envelopes.ID{}) { @@ -208,7 +208,7 @@ var commitCmd = &cobra.Command{ currentId := currentTransaction.ID() - err = repo.Write(ctx, currentTransaction) + err = repo.WriteTransaction(ctx, currentTransaction) if err != nil { logrus.Fatal(err) } @@ -372,7 +372,7 @@ func findDefaultAmount(ctx context.Context, targetDir string) (envelopes.Balance } var head envelopes.Transaction - err = repo.Load(ctx, id, &head) + err = repo.LoadTransaction(ctx, id, &head) if err != nil { return envelopes.Balance{}, err } @@ -526,4 +526,4 @@ func incrementAsset(target envelopes.Balance, asset envelopes.AssetType, magnitu } else { target[asset] = magnitude } -} \ No newline at end of file +} diff --git a/cmd/diff.go b/cmd/diff.go index 23c9a6e..a42c903 100644 --- a/cmd/diff.go +++ b/cmd/diff.go @@ -36,7 +36,7 @@ import ( type diffCmd struct { cobra.Command Context context.Context - Repo persist.RepositoryReader + Repo persist.RepositoryReader } func init() { @@ -55,12 +55,12 @@ func newDiffCmdWithContext(ctx context.Context) *diffCmd { } retval.Command = cobra.Command{ - Use: "diff [refspec] [refspec]", - Short: "Finds the difference between two states, be they from the index or two transactions.", - Long: ``, - Args: retval.processArgs, + Use: "diff [refspec] [refspec]", + Short: "Finds the difference between two states, be they from the index or two transactions.", + Long: ``, + Args: retval.processArgs, PreRunE: setPagedCobraOutput, - Run: retval.run, + Run: retval.run, } return retval @@ -73,7 +73,7 @@ func (dc diffCmd) processArgs(cmd *cobra.Command, arg []string) error { for _, rs := range arg { id, err := persist.Resolve(dc.Context, dc.Repo, persist.RefSpec(rs)) - if err != nil || id.Equal(envelopes.ID{}){ + if err != nil || id.Equal(envelopes.ID{}) { return fmt.Errorf("%q is not a valid refspec", rs) } } @@ -82,7 +82,7 @@ func (dc diffCmd) processArgs(cmd *cobra.Command, arg []string) error { func (dc diffCmd) run(cmd *cobra.Command, args []string) { var err error - defer func(){ + defer func() { if err != nil { logrus.Error(err) return @@ -126,7 +126,7 @@ func getDiffStates(ctx context.Context, args []string, indexRoot string) (*envel return nil, err } var target envelopes.Transaction - err = repo.Load(ctx, targetID, &target) + err = repo.LoadTransaction(ctx, targetID, &target) if err != nil { return nil, err } @@ -142,7 +142,7 @@ func getDiffStates(ctx context.Context, args []string, indexRoot string) (*envel } left, err = index.LoadState(ctx, indexRoot) - if err != nil{ + if err != nil { return nil, nil, err } case 1: // Compare current index against specified refspec diff --git a/cmd/show.go b/cmd/show.go index 5dcf126..57c03bd 100644 --- a/cmd/show.go +++ b/cmd/show.go @@ -61,7 +61,7 @@ for the sake of brevity. This command shows all known details of a transaction.` } var target envelopes.Transaction - err = repo.Load(ctx, targetID, &target) + err = repo.LoadTransaction(ctx, targetID, &target) if err != nil { logrus.Fatal(err) } diff --git a/go.mod b/go.mod index 79cbc8e..4d2a2bb 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,7 @@ module github.com/marstr/baronial require ( - github.com/BurntSushi/toml v0.3.1 // indirect - github.com/inconshreveable/mousetrap v1.0.0 // indirect - github.com/marstr/envelopes v0.4.0 + github.com/marstr/envelopes v0.5.0 github.com/marstr/units v1.0.1 github.com/mitchellh/go-homedir v1.1.0 github.com/sirupsen/logrus v1.2.0 @@ -12,4 +10,24 @@ require ( golang.org/x/crypto v0.1.0 ) -go 1.13 +require ( + github.com/BurntSushi/toml v0.3.1 // indirect + github.com/fsnotify/fsnotify v1.4.7 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect + github.com/magiconair/properties v1.8.0 // indirect + github.com/marstr/collection/v2 v2.0.0-preview1 // indirect + github.com/mitchellh/mapstructure v1.1.2 // indirect + github.com/pelletier/go-toml v1.2.0 // indirect + github.com/spf13/afero v1.1.2 // indirect + github.com/spf13/cast v1.3.0 // indirect + github.com/spf13/jwalterweatherman v1.0.0 // indirect + github.com/spf13/pflag v1.0.3 // indirect + golang.org/x/sys v0.1.0 // indirect + golang.org/x/term v0.1.0 // indirect + golang.org/x/text v0.4.0 // indirect + gopkg.in/yaml.v2 v2.2.2 // indirect +) + +go 1.20 diff --git a/go.sum b/go.sum index 6564d1a..5019356 100644 --- a/go.sum +++ b/go.sum @@ -16,10 +16,10 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGi github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/marstr/collection v1.1.1 h1:NJgrWXrjYWkrAr/bAp6LVCT+NvrZpE8URGFy7R7CBIA= -github.com/marstr/collection v1.1.1/go.mod h1:yGFnCtb7iWtkdragXuuvnQzBQ8DAu+awhmE7F4kRgaQ= -github.com/marstr/envelopes v0.4.0 h1:KmeD02hqQ+49tiV5nIJDEo61eoHJKL9Up0NRxES7Rro= -github.com/marstr/envelopes v0.4.0/go.mod h1:EQOwsSRBbGf+0/1PykFWpAlp63I6fen9yR4/EtXGjPY= +github.com/marstr/collection/v2 v2.0.0-preview1 h1:uGQOw5nm/kRF00dqIOCXfNOUsioiSHN1VPnLU8emen8= +github.com/marstr/collection/v2 v2.0.0-preview1/go.mod h1:53MC3XxVQ/rUxiNS4bZTvx5QJSWNgZMqPFMJomGKob4= +github.com/marstr/envelopes v0.5.0 h1:kfJVWa8C26ZXgnjdpMoOeqxJuzVqFDht4pS+HS50Zsw= +github.com/marstr/envelopes v0.5.0/go.mod h1:uLRCVLFyjZPVfWMF48zisetTalGIt+I0Sm+ui6rZmB0= github.com/marstr/units v1.0.1 h1:J1oBku8rInztZY9IO0W2fS1bZ60UotlmBLbyvyZLoSU= github.com/marstr/units v1.0.1/go.mod h1:B1/IxDKETT7FwLuU0ZOvdPePP9chjt0PLTt+qeVARJ8= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -49,42 +49,19 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= diff --git a/internal/format/transaction.go b/internal/format/transaction.go index bdf408f..bb49ecf 100644 --- a/internal/format/transaction.go +++ b/internal/format/transaction.go @@ -90,7 +90,7 @@ func PrettyPrintTransaction( impacts = envelopes.Impact(*subject.State) } else { var parent envelopes.Transaction - err := loader.Load(ctx, subject.Parents[0], &parent) + err := loader.LoadTransaction(ctx, subject.Parents[0], &parent) if err != nil { return err } @@ -147,12 +147,12 @@ func PrettyPrintTransaction( // PrettyPrintImpact writes the details of an envelopes.Impact to the provided io.Writer. func PrettyPrintImpact(output io.Writer, impacts envelopes.Impact) (err error) { - _ , err = fmt.Fprintf(output, "\tAccounts:\n") + _, err = fmt.Fprintf(output, "\tAccounts:\n") if err != nil { return } for acc, delta := range impacts.Accounts { - _ , err = fmt.Fprintf(output, "\t\t%s: %s\n", acc, delta) + _, err = fmt.Fprintf(output, "\t\t%s: %s\n", acc, delta) if err != nil { return } @@ -166,9 +166,9 @@ func PrettyPrintImpact(output io.Writer, impacts envelopes.Impact) (err error) { } sort.Strings(sortedBudgetNames) - _ , err = fmt.Fprintf(output, "\tBudgets:\n") + _, err = fmt.Fprintf(output, "\tBudgets:\n") for _, name := range sortedBudgetNames { - _ , err = fmt.Fprintf(output, "\t\t%s: %s\n", name, flattened[name]) + _, err = fmt.Fprintf(output, "\t\t%s: %s\n", name, flattened[name]) if err != nil { return }