Skip to content

Commit

Permalink
rename commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Hbbb committed Feb 3, 2024
1 parent 41c8a21 commit bfeabb8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"github.com/spf13/cobra"
)

func LoadPlaidDataCmd(ctx context.Context) *cobra.Command {
func ExtractCmd(ctx context.Context) *cobra.Command {
command := cobra.Command{
Use: "plaid-data",
Short: "load data from plaid",
Use: "extract",
Short: "fetch data from the Plaid API and save it",
RunE: func(cmd *cobra.Command, args []string) error {
isSandBox, err := cmd.Flags().GetBool("sandbox")
if err != nil {
Expand Down
54 changes: 47 additions & 7 deletions cli/internal/cmd/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,59 @@ package cmd

import (
"context"
"database/sql"
"os"
"path/filepath"
"time"

_ "github.com/mattn/go-sqlite3"
"github.com/politicker/budgeted/internal/csv"
"github.com/politicker/budgeted/internal/db"
"github.com/spf13/cobra"
)

func LoadCmd(ctx context.Context) *cobra.Command {
cmd := &cobra.Command{
command := cobra.Command{
Use: "load",
Short: "load data",
}
Short: "load CSV data into SQLite database",
RunE: func(cmd *cobra.Command, args []string) error {

driver, err := sql.Open("sqlite3", filepath.Join(os.Getenv("HOME"), ".config", "budgeted", "db.sqlite"))
if err != nil {
return err
}

queries := db.New(driver)
ctx := context.Background()

err = queries.ImportLogCreate(ctx, time.Now())
if err != nil {
return err
}

importLogId, err := queries.ImportLogGetLastInsertID(ctx)
if err != nil {
return err
}

cmd.AddCommand(LoadCsvCmd(ctx))
cmd.AddCommand(LoadPlaidDataCmd(ctx))
cmd.AddCommand(LoadSqliteCmd())
err = csv.LoadTransactions(ctx, queries, importLogId)
if err != nil {
return err
}

err = csv.LoadAccounts(ctx, queries, importLogId)
if err != nil {
return err
}

err = queries.ImportLogComplete(ctx, importLogId)
if err != nil {
return err
}

return nil
},
}

return cmd
return &command
}
60 changes: 0 additions & 60 deletions cli/internal/cmd/load.sqlite.go

This file was deleted.

2 changes: 2 additions & 0 deletions cli/internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func Execute(ctx context.Context) error {
rootCmd.AddCommand(APICmd(ctx))
rootCmd.AddCommand(SchedulerCmd(ctx))
rootCmd.AddCommand(WorkerCmd(ctx))
rootCmd.AddCommand(ExtractCmd(ctx))
rootCmd.AddCommand(TransformCmd(ctx))
rootCmd.AddCommand(LoadCmd(ctx))

// I'm not sure what this is for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"github.com/spf13/cobra"
)

func LoadCsvCmd(ctx context.Context) *cobra.Command {
func TransformCmd(ctx context.Context) *cobra.Command {
return &cobra.Command{
Use: "csv",
Short: "load data into csv",
Use: "transform",
Short: "transform data from json to csv",
RunE: func(cmd *cobra.Command, args []string) error {
jsonStorage, csvStorage, err := cmdutil.Dirs()
if err != nil {
Expand Down

0 comments on commit bfeabb8

Please sign in to comment.