Skip to content

Commit

Permalink
Merge pull request #53 from karl-cardenas-coding/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
karl-cardenas-coding authored Jul 7, 2020
2 parents b6532b2 + 5be711d commit b9da3f7
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 33 deletions.
12 changes: 10 additions & 2 deletions cmd/categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/jedib0t/go-pretty/table"
"github.com/karl-cardenas-coding/disaster-cli/library"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -57,9 +58,16 @@ The returned category may be used with the --filter flag for the event cmd.`,
}

if outputFlag == "json" {
json, err := json.Marshal(records)
json, err := json.MarshalIndent(records, "", "")
if err != nil {
fmt.Println(err)
log.WithFields(log.Fields{
"package": "cmd",
"file": "categories.go",
"parent_function": "Run",
"function": "json.Marshal",
"error": err,
"data": fmt.Sprint(cmd, "./documentation/"),
}).Error("Error marshaling JSON", ISSUE_MSG)
}
os.Stdout.Write(json)
}
Expand Down
42 changes: 38 additions & 4 deletions cmd/disaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package cmd

import (
"fmt"
"log"
"os"

log "github.com/sirupsen/logrus"

"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
Expand All @@ -19,6 +20,10 @@ var (
DownloadTempPath string
)

const (
ISSUE_MSG = " Please open up a Github issue to report this error! https://github.com/karl-cardenas-coding/disaster-cli"
)

var rootCmd = &cobra.Command{
Use: "disaster",
Short: "A CLI tool for determining natural catastrophe near you, or a location specified",
Expand All @@ -28,13 +33,27 @@ var rootCmd = &cobra.Command{
if generateDocFlag {
err := doc.GenMarkdownTree(cmd, "./documentation/")
if err != nil {
log.Fatal(err)
log.WithFields(log.Fields{
"package": "cmd",
"file": "disaster.go",
"parent_function": "generateDocFlag",
"function": "doc.GenMarkdownTree",
"error": err,
"data": fmt.Sprint(cmd, "./documentation/"),
}).Fatal("Error generating markdown content", ISSUE_MSG)
}
}

err := cmd.Help()
if err != nil {
log.Fatal(err)
log.WithFields(log.Fields{
"package": "cmd",
"file": "disaster.go",
"parent_function": "generateDocFlag",
"function": "cmd.Help",
"error": err,
"data": nil,
}).Fatal("Error outputting help!", ISSUE_MSG)
}
},
}
Expand All @@ -46,11 +65,26 @@ func init() {
eventsCmd.Flags().BoolVarP(&DisplayMapFlag, "display-map", "d", false, "Displays the Google Maps URL")
eventsCmd.Flags().StringSliceVarP(&FiltersFlag, "filter", "f", []string{}, "filter events by passing in categories (comma seperated")
updateCmd.Flags().StringVarP(&DownloadTempPath, "temp-location", "l", "", "Specify the temporary directory to use for the update process")

// Establish logging default
log.SetFormatter(&log.TextFormatter{
DisableColors: false,
FullTimestamp: true,
})
log.SetOutput(os.Stdout)

log.SetLevel(log.WarnLevel)
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
log.WithFields(log.Fields{
"package": "cmd",
"file": "disaster.go",
"function": "Execute",
"error": err,
"data": nil,
}).Fatal("Error executing the CLI!", ISSUE_MSG)
os.Exit(1)
}
}
23 changes: 19 additions & 4 deletions cmd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/jedib0t/go-pretty/table"
"github.com/karl-cardenas-coding/disaster-cli/library"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -73,19 +74,33 @@ func outputJSON(records library.EventResponse, filters []string) {

}

json, err := json.Marshal(&list)
json, err := json.MarshalIndent(&list, "", "")
if err != nil {
fmt.Println(err)
log.WithFields(log.Fields{
"package": "cmd",
"file": "events.go",
"parent_function": "outputJSON",
"function": "json.Marshal",
"error": err,
"data": list,
}).Error("Error marshalling JSON", ISSUE_MSG)
}
os.Stdout.Write(json)

}

if len(filters) == 0 {

json, err := json.Marshal(&records)
json, err := json.MarshalIndent(&records, "", "")
if err != nil {
fmt.Println(err)
log.WithFields(log.Fields{
"package": "cmd",
"file": "events.go",
"parent_function": "outputJSON",
"function": "json.Marshal",
"error": err,
"data": records,
}).Error("Error marshalling JSON", ISSUE_MSG)
}
os.Stdout.Write(json)

Expand Down
Loading

0 comments on commit b9da3f7

Please sign in to comment.