Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions cmd/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"path"
"path/filepath"
"sort"
"time"

"github.com/marstr/envelopes"
"github.com/sirupsen/logrus"
Expand All @@ -44,22 +43,8 @@ var balanceCmd = &cobra.Command{
Aliases: []string{"bal", "b"},
Short: "Scours a baronial directory (or subdirectory) for balance information.",
Run: func(cmd *cobra.Command, args []string) {
var timeout time.Duration
var err error
timeout, err = cmd.Flags().GetDuration(timeoutFlag)
if err != nil {
logrus.Fatal(err)
}

var ctx context.Context
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), timeout)
defer cancel()

} else {
ctx = context.Background()
}
ctx, cancel := RootContext(cmd)
defer cancel()

var targetDir string
if len(args) > 0 {
Expand All @@ -68,6 +53,7 @@ var balanceCmd = &cobra.Command{
targetDir = "."
}

var err error
targetDir, err = filepath.Abs(targetDir)
if err != nil {
logrus.Fatal(err)
Expand Down
19 changes: 3 additions & 16 deletions cmd/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"io"
"os"
"path"
"time"

"github.com/marstr/envelopes"
"github.com/marstr/envelopes/persist"
Expand All @@ -40,22 +39,10 @@ var branchCmd = &cobra.Command{
Short: "Creates a branch with a given name.",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var timeout time.Duration
var err error
timeout, err = cmd.Flags().GetDuration(timeoutFlag)
if err != nil {
logrus.Fatal(err)
}

var ctx context.Context
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), timeout)
defer cancel()
} else {
ctx = context.Background()
}
ctx, cancel := RootContext(cmd)
defer cancel()

var err error
var indexRootDir string
indexRootDir, err = index.RootDirectory(".")
if err != nil {
Expand Down
20 changes: 2 additions & 18 deletions cmd/bring-to.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package cmd

import (
"context"
"time"

"github.com/marstr/baronial/internal/index"
"github.com/marstr/envelopes"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -31,21 +28,8 @@ func init() {
}

func RunBringTo(cmd *cobra.Command, args []string) error {
var timeout time.Duration
var err error
timeout, err = cmd.Flags().GetDuration(timeoutFlag)
if err != nil {
logrus.Fatal(err)
}

var ctx context.Context
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), timeout)
defer cancel()
} else {
ctx = context.Background()
}
ctx, cancel := RootContext(cmd)
defer cancel()

desiredBal, err := envelopes.ParseBalance([]byte(args[0]))
if err != nil {
Expand Down
21 changes: 3 additions & 18 deletions cmd/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
package cmd

import (
"context"
"path"
"time"

"github.com/marstr/envelopes"
"github.com/marstr/envelopes/persist"
Expand All @@ -35,24 +33,11 @@ var checkoutCmd = &cobra.Command{
Short: "Resets the index to show the balances at a particular transaction.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var timeout time.Duration
var err error
timeout, err = cmd.Flags().GetDuration(timeoutFlag)
if err != nil {
logrus.Fatal(err)
}

var ctx context.Context
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), timeout)
defer cancel()

} else {
ctx = context.Background()
}
ctx, cancel := RootContext(cmd)
defer cancel()

var root string
var err error
root, err = index.RootDirectory(".")
if err != nil {
logrus.Fatal(err)
Expand Down
18 changes: 2 additions & 16 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,8 @@ var commitCmd = &cobra.Command{
return cobra.NoArgs(cmd, args)
},
Run: func(cmd *cobra.Command, _ []string) {
var timeout time.Duration
var err error
timeout, err = cmd.Flags().GetDuration(timeoutFlag)
if err != nil {
logrus.Fatal(err)
}

var ctx context.Context
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), timeout)
defer cancel()

} else {
ctx = context.Background()
}
ctx, cancel := RootContext(cmd)
defer cancel()

targetDir, err := index.RootDirectory(".")
if err != nil {
Expand Down
40 changes: 5 additions & 35 deletions cmd/credit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
package cmd

import (
"context"
"fmt"
"time"

"github.com/marstr/envelopes"
"github.com/sirupsen/logrus"
Expand All @@ -33,22 +31,8 @@ var creditCmd = &cobra.Command{
Short: "Makes funds available for one or more category of spending.",
Args: creditDebitArgValidation,
Run: func(cmd *cobra.Command, args []string) {
var timeout time.Duration
var err error
timeout, err = cmd.Flags().GetDuration(timeoutFlag)
if err != nil {
logrus.Fatal(err)
}

var ctx context.Context
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), timeout)
defer cancel()

} else {
ctx = context.Background()
}
ctx, cancel := RootContext(cmd)
defer cancel()

rawMagnitude := args[0]
magnitude, err := envelopes.ParseBalance([]byte(rawMagnitude))
Expand Down Expand Up @@ -76,28 +60,14 @@ func init() {
}

func creditDebitArgValidation(cmd *cobra.Command, args []string) error {
var timeout time.Duration
var err error
timeout, err = cmd.Flags().GetDuration(timeoutFlag)
if err != nil {
logrus.Fatal(err)
}

var ctx context.Context
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), timeout)
defer cancel()

} else {
ctx = context.Background()
}
ctx, cancel := RootContext(cmd)
defer cancel()

if argCount := len(args); argCount < 2 {
return fmt.Errorf("too few arguments (%d). %q requires at least a balance and one budget or account", argCount, cmd.Name())
}

_, err = envelopes.ParseBalance([]byte(args[0]))
_, err := envelopes.ParseBalance([]byte(args[0]))
if err != nil {
return fmt.Errorf("%q not recognized as an amount", args[0])
}
Expand Down
21 changes: 2 additions & 19 deletions cmd/debit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
package cmd

import (
"context"
"time"

"github.com/marstr/envelopes"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -32,22 +29,8 @@ var debitCmd = &cobra.Command{
Short: `Removes funds from a category of spending.`,
Args: creditDebitArgValidation,
Run: func(cmd *cobra.Command, args []string) {
var timeout time.Duration
var err error
timeout, err = cmd.Flags().GetDuration(timeoutFlag)
if err != nil {
logrus.Fatal(err)
}

var ctx context.Context
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), timeout)
defer cancel()

} else {
ctx = context.Background()
}
ctx, cancel := RootContext(cmd)
defer cancel()

rawMagnitude := args[0]
magnitude, err := envelopes.ParseBalance([]byte(rawMagnitude))
Expand Down
22 changes: 3 additions & 19 deletions cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"errors"
"path"
"time"

"github.com/marstr/envelopes"
"github.com/marstr/envelopes/persist"
Expand All @@ -40,25 +39,10 @@ var diffCmd = &cobra.Command{
Args: cobra.MaximumNArgs(2),
PreRunE: setPagedCobraOutput,
Run: func(cmd *cobra.Command, args []string) {
var timeout time.Duration
var err error
timeout, err = cmd.Flags().GetDuration(timeoutFlag)
if err != nil {
logrus.Fatal(err)
}

var ctx context.Context
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), timeout)
defer cancel()

} else {
ctx = context.Background()
}
ctx, cancel := RootContext(cmd)
defer cancel()

var repoRoot string
repoRoot, err = index.RootDirectory(".")
repoRoot, err := index.RootDirectory(".")
if err != nil {
return
}
Expand Down
23 changes: 3 additions & 20 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
package cmd

import (
"context"
"os"
"time"

"github.com/marstr/envelopes"
"github.com/marstr/envelopes/persist"
Expand All @@ -34,22 +32,8 @@ var initCmd = &cobra.Command{
Short: "Creates a new Baronial repository in the current working directory.",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
var timeout time.Duration
var err error
timeout, err = cmd.Flags().GetDuration(timeoutFlag)
if err != nil {
logrus.Fatal(err)
}

var ctx context.Context
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), timeout)
defer cancel()

} else {
ctx = context.Background()
}
ctx, cancel := RootContext(cmd)
defer cancel()

const initCmdFailurePrefix = "unable to initialize repository: "

Expand All @@ -71,8 +55,7 @@ var initCmd = &cobra.Command{
}
}

var repo persist.RepositoryReaderWriter
repo, err = filesystem.OpenRepositoryWithCache(ctx, index.RepoName, 10000)
repo, err := filesystem.OpenRepositoryWithCache(ctx, index.RepoName, 10000)
if err != nil {
logrus.Fatal(err)
}
Expand Down
22 changes: 3 additions & 19 deletions cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/marstr/envelopes"
"github.com/marstr/envelopes/persist"
Expand All @@ -43,25 +42,10 @@ var logCmd = &cobra.Command{
},
PreRunE: setPagedCobraOutput,
Run: func(cmd *cobra.Command, args []string) {
var timeout time.Duration
var err error
timeout, err = cmd.Flags().GetDuration(timeoutFlag)
if err != nil {
logrus.Fatal(err)
}

var ctx context.Context
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), timeout)
defer cancel()

} else {
ctx = context.Background()
}
ctx, cancel := RootContext(cmd)
defer cancel()

var root string
root, err = index.RootDirectory(".")
root, err := index.RootDirectory(".")
if err != nil {
logrus.Error(err)
return
Expand Down
Loading
Loading