From c4059088586154b97c4c254f017ab1d958ecdaca Mon Sep 17 00:00:00 2001 From: Gaurav Gahlot Date: Fri, 7 Oct 2022 22:09:43 +0530 Subject: [PATCH 1/7] remove bash-completion.sh --- cmd/bash-completion.sh | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 cmd/bash-completion.sh diff --git a/cmd/bash-completion.sh b/cmd/bash-completion.sh deleted file mode 100644 index 05164505..00000000 --- a/cmd/bash-completion.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -# __bashcompembed_custom_func is a function that is called by bash-completion to get a list of completions used by the -# legacy bash autocomplete system. This function is irrelevant to the new bash autocomplete system and should do -# nothing. -__bashcompembed_custom_func() { - ehco "This function is irrelevant to the new bash autocomplete system and should return nothing." -} From efd131e6770e0b1c177469abf6cf6fa4cf5af17a Mon Sep 17 00:00:00 2001 From: Gaurav Gahlot Date: Fri, 7 Oct 2022 23:18:55 +0530 Subject: [PATCH 2/7] installable gidari binary --- cmd/gidari/cmd/root.go | 86 ++++++++++++++++++++++++++++++++++++++++++ cmd/gidari/main.go | 22 +++++++++++ 2 files changed, 108 insertions(+) create mode 100644 cmd/gidari/cmd/root.go create mode 100644 cmd/gidari/main.go diff --git a/cmd/gidari/cmd/root.go b/cmd/gidari/cmd/root.go new file mode 100644 index 00000000..b05a2e86 --- /dev/null +++ b/cmd/gidari/cmd/root.go @@ -0,0 +1,86 @@ +// Copyright 2022 The Gidari Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +package cmd + +import ( + "context" + "fmt" + "os" + "strings" + + "github.com/alpine-hodler/gidari" + "github.com/alpine-hodler/gidari/version" + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +const ( + flagConfig = "config" + flagVerbose = "verbose" +) + +var ( + configFilepath string // configFilepath is the path to the configuration file. + verbose bool // verbose is a flag that enables verbose logging. +) + +var rootCMD = &cobra.Command{ + Long: "Gidari is a tool for querying web APIs and persisting resultant data onto local storage\n" + + "using a configuration file.", + + Use: "gidari", + Short: "Persist data from the web to your database", + Example: "gidari --config config.yaml", + Version: version.Gidari, + PreRunE: func(cmd *cobra.Command, args []string) error { + v, err := cmd.Flags().GetString(flagConfig) + if err != nil { + return err + } + + if !strings.HasSuffix(v, ".yaml") && !strings.HasSuffix(v, ".yml") { + return fmt.Errorf("configuration must be a YAML document") + } + + return nil + }, + RunE: runE, +} + +func Execute() error { + rootCMD.PersistentFlags().StringVarP(&configFilepath, flagConfig, "c", "", "path to configuration") + rootCMD.PersistentFlags().BoolVar(&verbose, flagVerbose, false, "print log data as the binary executes") + + _ = rootCMD.MarkPersistentFlagRequired(flagConfig) + + return rootCMD.Execute() +} + +func runE(cmd *cobra.Command, _ []string) error { + file, err := os.Open(configFilepath) + if err != nil { + return err + } + + cfg, err := gidari.NewConfig(context.Background(), file) + if err != nil { + return err + } + + if verbose { + cfg.Logger.SetOutput(os.Stdout) + cfg.Logger.SetLevel(logrus.InfoLevel) + } + + err = gidari.Transport(context.Background(), cfg) + if err != nil { + return err + } + + return nil +} diff --git a/cmd/gidari/main.go b/cmd/gidari/main.go new file mode 100644 index 00000000..707d6a79 --- /dev/null +++ b/cmd/gidari/main.go @@ -0,0 +1,22 @@ +// Copyright 2022 The Gidari Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +package main + +import ( + "fmt" + "os" + + "github.com/alpine-hodler/gidari/cmd/gidari/cmd" +) + +func main() { + if err := cmd.Execute(); err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } +} From a4edf730a82a529fef890650f728ed53ad08bd94 Mon Sep 17 00:00:00 2001 From: Gaurav Gahlot Date: Fri, 7 Oct 2022 23:19:34 +0530 Subject: [PATCH 3/7] remove redundant files --- cmd/.gitignore | 1 - cmd/gidari.go | 78 -------------------------------------------------- 2 files changed, 79 deletions(-) delete mode 100644 cmd/.gitignore delete mode 100644 cmd/gidari.go diff --git a/cmd/.gitignore b/cmd/.gitignore deleted file mode 100644 index f8c56cd2..00000000 --- a/cmd/.gitignore +++ /dev/null @@ -1 +0,0 @@ -gidari diff --git a/cmd/gidari.go b/cmd/gidari.go deleted file mode 100644 index cce72f72..00000000 --- a/cmd/gidari.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2022 The Gidari Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -package main - -import ( - "context" - _ "embed" // Embed external data. - "log" - "os" - - "github.com/alpstable/gidari" - "github.com/alpstable/gidari/version" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" -) - -//go:embed bash-completion.sh -var bashCompletion string - -func main() { - // configFilepath is the path to the configuration file. - var configFilepath string - - // verbose is a flag that enables verbose logging. - var verbose bool - - cmd := &cobra.Command{ - Long: "Gidari is a tool for querying web APIs and persisting resultant data onto local storage\n" + - "using a configuration file.", - - Use: "gidari", - Short: "Persisted data from the web to your database", - Example: "gidari --config config.yaml", - BashCompletionFunction: bashCompletion, - Deprecated: "", - Version: version.Gidari, - - Run: func(_ *cobra.Command, args []string) { run(configFilepath, verbose, args) }, - } - - cmd.Flags().StringVar(&configFilepath, "config", "c", "path to configuration") - cmd.Flags().BoolVar(&verbose, "verbose", false, "print log data as the binary executes") - - if err := cmd.MarkFlagRequired("config"); err != nil { - logrus.Fatalf("error marking flag as required: %v", err) - } - - if err := cmd.Execute(); err != nil { - log.Fatal(err) - } -} - -func run(configFilepath string, verboseLogging bool, _ []string) { - file, err := os.Open(configFilepath) - if err != nil { - log.Fatalf("error opening config file %s: %v", configFilepath, err) - } - - cfg, err := gidari.NewConfig(context.Background(), file) - if err != nil { - log.Fatalf("error creating new config: %v", err) - } - - if verboseLogging { - cfg.Logger.SetOutput(os.Stdout) - cfg.Logger.SetLevel(logrus.InfoLevel) - } - - err = gidari.Transport(context.Background(), cfg) - if err != nil { - log.Fatalf("failed to transport data: %v", err) - } -} From 19c0cff766e7a66e2d0528df0aa89cb1a768159d Mon Sep 17 00:00:00 2001 From: Gaurav Gahlot Date: Fri, 7 Oct 2022 23:19:51 +0530 Subject: [PATCH 4/7] update Makefile and .gitignore --- .gitignore | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 032c74d8..49e5a03d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ bazel-bin bazel-out bazel-testlogs bazel-driver -gidari +gidari-cli diff --git a/Makefile b/Makefile index 8bd4c362..d6a25408 100755 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ export GO111MODULE=on default: chmod +rwx scripts/*.sh - $(GC) build cmd/gidari.go + $(GC) build -o gidari-cli cmd/gidari/main.go # containers build the docker containers for performing integration tests. .PHONY: containers From 3faa9fae667828da26c5981da7f34eac2f04447c Mon Sep 17 00:00:00 2001 From: Gaurav Gahlot Date: Fri, 7 Oct 2022 23:25:16 +0530 Subject: [PATCH 5/7] update README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c9baf7fa..e157f114 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ Gidari is a "web-to-storage" tool for querying web APIs and persisting the resul ## Installation -TODO +```sh +go install github.com/alpine-hodler/gidari/cmd/gidari@latest +``` ## Usage From 93cfcc83ef28ceb6cd259c2630ef855e321d01f7 Mon Sep 17 00:00:00 2001 From: Gaurav Gahlot Date: Fri, 7 Oct 2022 23:42:36 +0530 Subject: [PATCH 6/7] make lint happy --- cmd/gidari/cmd/root.go | 65 ++++++++++++++++++++++-------------------- cmd/gidari/main.go | 2 +- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/cmd/gidari/cmd/root.go b/cmd/gidari/cmd/root.go index b05a2e86..6a388efc 100644 --- a/cmd/gidari/cmd/root.go +++ b/cmd/gidari/cmd/root.go @@ -9,7 +9,7 @@ package cmd import ( "context" - "fmt" + "errors" "os" "strings" @@ -24,44 +24,47 @@ const ( flagVerbose = "verbose" ) -var ( - configFilepath string // configFilepath is the path to the configuration file. - verbose bool // verbose is a flag that enables verbose logging. -) - -var rootCMD = &cobra.Command{ - Long: "Gidari is a tool for querying web APIs and persisting resultant data onto local storage\n" + - "using a configuration file.", - - Use: "gidari", - Short: "Persist data from the web to your database", - Example: "gidari --config config.yaml", - Version: version.Gidari, - PreRunE: func(cmd *cobra.Command, args []string) error { - v, err := cmd.Flags().GetString(flagConfig) - if err != nil { - return err - } - - if !strings.HasSuffix(v, ".yaml") && !strings.HasSuffix(v, ".yml") { - return fmt.Errorf("configuration must be a YAML document") - } - - return nil - }, - RunE: runE, -} +func RootCommand() *cobra.Command { + var ( + configFilepath string // configFilepath is the path to the configuration file. + verbose bool // verbose is a flag that enables verbose logging. + ) + + rootCMD := &cobra.Command{ + Long: "Gidari is a tool for querying web APIs and persisting resultant data onto local storage\n" + + "using a configuration file.", + + Use: "gidari", + Short: "Persist data from the web to your database", + Example: "gidari --config config.yaml", + Version: version.Gidari, + PreRunE: func(cmd *cobra.Command, args []string) error { + value, err := cmd.Flags().GetString(flagConfig) + if err != nil { + //nolint:wrapcheck // need not wrap the error + return err + } + + if !strings.HasSuffix(value, ".yaml") && !strings.HasSuffix(value, ".yml") { + //nolint:goerr113 // don't have static error + return errors.New("configuration must be a YAML document") + } + + return nil + }, + RunE: func(_ *cobra.Command, args []string) error { return runE(configFilepath, verbose) }, + } -func Execute() error { rootCMD.PersistentFlags().StringVarP(&configFilepath, flagConfig, "c", "", "path to configuration") rootCMD.PersistentFlags().BoolVar(&verbose, flagVerbose, false, "print log data as the binary executes") _ = rootCMD.MarkPersistentFlagRequired(flagConfig) - return rootCMD.Execute() + return rootCMD } -func runE(cmd *cobra.Command, _ []string) error { +//nolint:wrapcheck // need not wrap the error +func runE(configFilepath string, verbose bool) error { file, err := os.Open(configFilepath) if err != nil { return err diff --git a/cmd/gidari/main.go b/cmd/gidari/main.go index 707d6a79..00a2baea 100644 --- a/cmd/gidari/main.go +++ b/cmd/gidari/main.go @@ -15,7 +15,7 @@ import ( ) func main() { - if err := cmd.Execute(); err != nil { + if err := cmd.RootCommand().Execute(); err != nil { fmt.Fprintln(os.Stderr, err.Error()) os.Exit(1) } From 5facc0fba28408b2b25204473b9c7380c5f2d212 Mon Sep 17 00:00:00 2001 From: Gaurav Gahlot Date: Mon, 10 Oct 2022 10:50:42 +0530 Subject: [PATCH 7/7] update package path Signed-off-by: Gaurav Gahlot --- cmd/gidari/cmd/root.go | 4 ++-- cmd/gidari/main.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/gidari/cmd/root.go b/cmd/gidari/cmd/root.go index 6a388efc..1111c21e 100644 --- a/cmd/gidari/cmd/root.go +++ b/cmd/gidari/cmd/root.go @@ -13,8 +13,8 @@ import ( "os" "strings" - "github.com/alpine-hodler/gidari" - "github.com/alpine-hodler/gidari/version" + "github.com/alpstable/gidari" + "github.com/alpstable/gidari/version" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cmd/gidari/main.go b/cmd/gidari/main.go index 00a2baea..e1f8a90b 100644 --- a/cmd/gidari/main.go +++ b/cmd/gidari/main.go @@ -11,7 +11,7 @@ import ( "fmt" "os" - "github.com/alpine-hodler/gidari/cmd/gidari/cmd" + "github.com/alpstable/gidari/cmd/gidari/cmd" ) func main() {