diff --git a/.github/workflows/releaser.yml b/.github/workflows/releaser.yml new file mode 100644 index 0000000..7053731 --- /dev/null +++ b/.github/workflows/releaser.yml @@ -0,0 +1,38 @@ +name: goreleaser + +on: + push: + # run only against tags + tags: + - '*' + +permissions: + contents: write + # packages: write + # issues: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: git fetch --force --tags + - uses: actions/setup-go@v3 + with: + go-version: stable + cache: true + # More assembly might be required: Docker logins, GPG, etc. It all depends + # on your needs. + - uses: goreleaser/goreleaser-action@v4 + with: + # either 'goreleaser' (default) or 'goreleaser-pro': + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.PUBLISHER_TOKEN }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' + # distribution: + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..55625e0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM alpine:latest + +RUN apk add --no-cache go + +COPY . . + +CMD ["go", "test", "-v", "github.com/marianina8/cli/cmd"] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index ecfe9df..7e3277a 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# cli +# Example CLI \ No newline at end of file diff --git a/cmd/convert.go b/cmd/convert.go new file mode 100644 index 0000000..aa1e64e --- /dev/null +++ b/cmd/convert.go @@ -0,0 +1,54 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "fmt" + "io/ioutil" + "os" + + "github.com/marianina8/cli/utils" + "github.com/spf13/cobra" +) + +// convertCmd represents the convert command +var convertCmd = &cobra.Command{ + Use: "convert", + Short: "Converts a JSON to YAML file", + Run: func(cmd *cobra.Command, args []string) { + // converts json to yaml by default + file := cmd.Flag("file").Value.String() + silence, _ := cmd.Flags().GetBool("silence") + output := cmd.Flag("output").Value.String() + + if file == "" { + fmt.Println("Please provide a JSON file to convert") + return + } + yamlData, err := utils.J2Ytransform(file) + if err != nil { + fmt.Fprint(cmd.ErrOrStderr(), "Error converting JSON to YAML") + os.Exit(1) + } + + if !silence { + fmt.Fprint(cmd.OutOrStdout(), string(yamlData)) + } + + if output != "" { + err = ioutil.WriteFile(output, yamlData, 0644) + if err != nil { + fmt.Fprintf(cmd.ErrOrStderr(), "Error writing YAML file: %v", err) + os.Exit(1) + } + } + }, +} + +func init() { + rootCmd.AddCommand(convertCmd) + convertCmd.PersistentFlags().StringP("file", "f", "", "JSON file to convert") + convertCmd.PersistentFlags().BoolP("silence", "s", false, "Silence the output") + convertCmd.PersistentFlags().StringP("output", "o", "", "Output file name") +} diff --git a/cmd/convert_test.go b/cmd/convert_test.go new file mode 100644 index 0000000..dbf3532 --- /dev/null +++ b/cmd/convert_test.go @@ -0,0 +1,60 @@ +package cmd + +import ( + "bytes" + "io" + "os" + "path/filepath" + "testing" + + "github.com/marianina8/cli/models" + "gopkg.in/yaml.v2" +) + +func TestConvert(t *testing.T) { + t.Run("Test successful convert", func(t *testing.T) { + b := bytes.NewBufferString("") + rootCmd.SetOut(b) + rootCmd.SetArgs([]string{"convert", "-f", "../example.json"}) + err := rootCmd.Execute() + if err != nil { + t.Fatal(err) + } + actualBytes, err := io.ReadAll(b) + if err != nil { + t.Fatal(err) + } + filePath := filepath.Join("..", "example.yaml") + expectedBytes, err := os.ReadFile(filePath) + if err != nil { + t.Fatal(err) + } + var workshop1, workshop2 models.Workshop + yaml.Unmarshal(actualBytes, &workshop1) + yaml.Unmarshal(expectedBytes, &workshop2) + if !(workshop1.Title == workshop2.Title && + workshop1.Instructors[0].Name == workshop2.Instructors[0].Name && + workshop1.Instructors[0].Email == workshop2.Instructors[0].Email && + workshop1.Instructors[1].Name == workshop2.Instructors[1].Name && + workshop1.Instructors[1].Email == workshop2.Instructors[1].Email) { + t.Fatalf("expected %v, got %v", workshop2, workshop1) + } + }) + + t.Run("Fail to convert", func(t *testing.T) { + b := bytes.NewBufferString("") + rootCmd.SetErr(b) + rootCmd.SetArgs([]string{"convert", "--random"}) + err := rootCmd.Execute() + if err == nil { + t.Fatalf("expected err (unknown flag) but got nil") + } + actualBytes, err := io.ReadAll(b) + if err != nil { + t.Fatal(err) + } + if string(actualBytes) != "Error: unknown flag: --random\n" { + t.Fatal(err) + } + }) +} diff --git a/cmd/dashboard.go b/cmd/dashboard.go new file mode 100644 index 0000000..484eeb7 --- /dev/null +++ b/cmd/dashboard.go @@ -0,0 +1,133 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "context" + "fmt" + + "github.com/mum4k/termdash" + "github.com/mum4k/termdash/align" + "github.com/mum4k/termdash/cell" + "github.com/mum4k/termdash/container" + "github.com/mum4k/termdash/linestyle" + "github.com/mum4k/termdash/terminal/tcell" + "github.com/mum4k/termdash/terminal/terminalapi" + "github.com/mum4k/termdash/widgets/button" + "github.com/mum4k/termdash/widgets/text" + "github.com/mum4k/termdash/widgets/textinput" + "github.com/spf13/cobra" +) + +// dashboardCmd represents the dashboard command +var dashboardCmd = &cobra.Command{ + Use: "dashboard", + Short: "An example dashboard", + Run: func(cmd *cobra.Command, args []string) { + terminalLayer, err := tcell.New(tcell.ColorMode(terminalapi.ColorMode256), tcell.ClearStyle(cell.ColorYellow, cell.ColorNavy)) + if err != nil { + fmt.Println(err) + } + defer terminalLayer.Close() + value := make(chan string) + rollingText, err := text.New(text.RollContent()) + if err != nil { + panic(err) + } + go rollText(rollingText, value) + leftContainer := container.Left( + container.Border(linestyle.Light), + container.PlaceWidget(rollingText), + ) + input, err := textinput.New( + textinput.Label("Input: "), + textinput.MaxWidthCells(20), + textinput.PlaceHolder("Enter text here"), + ) + if err != nil { + panic(err) + } + submitButton, err := button.New("Submit", func() error { + inputValue := input.ReadAndClear() + if inputValue != "" { + value <- inputValue + } + return nil + }) + if err != nil { + panic(err) + } + clearButton, err := button.New("Clear", func() error { + rollingText.Reset() + return nil + }) + if err != nil { + panic(err) + } + rightContainer := container.Right( + container.SplitHorizontal( + container.Top( + container.Border(linestyle.Light), + container.PlaceWidget(input), + container.AlignVertical(align.VerticalBottom), + container.MarginTop(3), + container.MarginBottom(3), + container.MarginRight(3), + container.MarginLeft(3), + ), + container.Bottom( + container.SplitVertical( + container.Left( + container.Border(linestyle.Light), + container.PlaceWidget(submitButton), + container.AlignVertical(align.VerticalTop), + ), + container.Right( + container.Border(linestyle.Light), + container.PlaceWidget(clearButton), + container.AlignVertical(align.VerticalTop), + ), + ), + ), + ), + ) + containerLayer, _ := container.New( + terminalLayer, + container.SplitVertical( + leftContainer, + rightContainer, + container.SplitPercent(60), + ), + ) + + ctx, cancel := context.WithCancel(context.Background()) + quitter := func(k *terminalapi.Keyboard) { + if k.Key == 'q' || k.Key == 'Q' { + cancel() + } + } + if err := termdash.Run(ctx, terminalLayer, containerLayer, termdash.KeyboardSubscriber(quitter)); err != nil { + panic(err) + } + + }, +} + +func init() { + rootCmd.AddCommand(dashboardCmd) +} + +func rollText(rollingText *text.Text, value <-chan string) { + for { + select { + case v := <-value: + err := rollingText.Write(v) + if err != nil { + panic(err) + } + default: + // no value on the channel, continue without blocking + } + } +} diff --git a/cmd/jsonToYaml.go b/cmd/jsonToYaml.go new file mode 100644 index 0000000..88858d9 --- /dev/null +++ b/cmd/jsonToYaml.go @@ -0,0 +1,52 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "fmt" + "io/ioutil" + "log" + "os" + + "github.com/marianina8/cli/utils" + "github.com/spf13/cobra" +) + +// jsonToYamlCmd represents the jsonToYaml command +var jsonToYamlCmd = &cobra.Command{ + Use: "jsonToYaml", + Short: "Converts json to yaml", + Aliases: []string{"j2y"}, + Run: func(cmd *cobra.Command, args []string) { + file := cmd.Flag("file").Value.String() + silence, _ := cmd.Flags().GetBool("silence") + output := cmd.Flag("output").Value.String() + + if file == "" { + fmt.Println("Please provide a JSON file to convert") + return + } + yamlData, err := utils.J2Ytransform(file) + if err != nil { + log.Fatalf("Error converting JSON to YAML: %v", err) + os.Exit(1) + } + + if !silence { + fmt.Println(string(yamlData)) + } + + if output != "" { + err = ioutil.WriteFile(output, yamlData, 0644) + if err != nil { + log.Fatalf("Error writing YAML file: %v", err) + os.Exit(1) + } + } + }, +} + +func init() { + convertCmd.AddCommand(jsonToYamlCmd) +} diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..b2cbc9f --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,50 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "os" + + "github.com/spf13/cobra" +) + +func RootCmd() *cobra.Command { + return rootCmd +} + +// rootCmd represents the base command when called without any subcommands +var rootCmd = &cobra.Command{ + Use: "cli", + Short: "A brief description of your application", + Long: `A longer description that spans multiple lines and likely contains +examples and usage of using your application. For example: + +Cobra is a CLI library for Go that empowers applications. +This application is a tool to generate the needed files +to quickly create a Cobra application.`, + // Uncomment the following line if your bare application + // has an action associated with it: + // Run: func(cmd *cobra.Command, args []string) { }, +} + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute() { + err := rootCmd.Execute() + if err != nil { + os.Exit(1) + } +} + +func init() { + // Here you will define your flags and configuration settings. + // Cobra supports persistent flags, which, if defined here, + // will be global for your application. + + // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.example11.yaml)") + + // Cobra also supports local flags, which will only run + // when this action is called directly. + rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} \ No newline at end of file diff --git a/cmd/store.go b/cmd/store.go new file mode 100644 index 0000000..edeca94 --- /dev/null +++ b/cmd/store.go @@ -0,0 +1,78 @@ +//go:build store + +package cmd + +import ( + "bytes" + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "os" + + "github.com/spf13/cobra" +) + +// storeCmd represents the store command +var storeCmd = &cobra.Command{ + Use: "store", + Short: "Stores JSON data online", + Long: `Uploads JSON data to JSONBIN.io for later retrieval`, + Run: func(cmd *cobra.Command, args []string) { + url := "https://api.jsonbin.io/v3/b" + apiKey := "$2b$10$mwv0UXTT5hhwULEj8KehZuhT1Vgn8tg0FP6K9zr24TMWwqJDL95.." + + fileVal := cmd.Flag("file").Value.String() + if fileVal == "" { + fmt.Println("Please provide a JSON file to upload") + return + } + file, err := os.Open(fileVal) + if err != nil { + fmt.Println("Erorr opening up file", err) + return + } + defer file.Close() + + jsonBytes, err := ioutil.ReadAll(file) + if err != nil { + fmt.Println("Error reading file", err) + return + } + + req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonBytes)) + if err != nil { + fmt.Println("Error creating request", err) + return + } + req.Header.Set("Content-Type", "application/json") + req.Header.Set("X-Master-Key", apiKey) + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + fmt.Println("Error sending request", err) + return + } + defer resp.Body.Close() + + var result map[string]interface{} + err = json.NewDecoder(resp.Body).Decode(&result) + if err != nil { + fmt.Println("Error decoding response", err) + } + if resp.StatusCode != http.StatusOK { + fmt.Println("Error storing JSON data. Received status: ", resp.Status) + return + } else { + fmt.Println("File saved online at JSONBIN.io with id:", result["metadata"].(map[string]interface{})["id"]) + return + } + + }, +} + +func init() { + storeCmd.Flags().StringP("file", "f", "", "JSON file to upload") + rootCmd.AddCommand(storeCmd) +} diff --git a/cmd/survey.go b/cmd/survey.go new file mode 100644 index 0000000..8708113 --- /dev/null +++ b/cmd/survey.go @@ -0,0 +1,66 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "fmt" + + "github.com/AlecAivazis/survey/v2" + "github.com/spf13/cobra" +) + +// surveyCmd represents the survey command +var surveyCmd = &cobra.Command{ + Use: "survey", + Short: "Prompts user for input", + Run: func(cmd *cobra.Command, args []string) { + var qs = []*survey.Question{ + { + Name: "name", + Prompt: &survey.Input{Message: "What is your name?"}, + Validate: survey.Required, + Transform: survey.Title, + }, + { + Name: "age", + Prompt: &survey.Input{Message: "How old are you?"}, + Validate: survey.Required, + }, + { + Name: "programminglanguage", + Prompt: &survey.Select{ + Message: "What is your favorite programming language?", + Options: []string{"Go", "Java", "C++", "Python", "Ruby"}, + Default: "Go", + }, + }, + } + answers := struct { + Name string + Age int + ProgrammingLanguage string `survey:"programminglanguage"` + }{} + + err := survey.Ask(qs, &answers) + if err != nil { + fmt.Println(err.Error()) + } + + fmt.Printf("%s's favorite language is %s.", answers.Name, answers.ProgrammingLanguage) + }, +} + +func init() { + rootCmd.AddCommand(surveyCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // surveyCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // surveyCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/cmd/yamlToJson.go b/cmd/yamlToJson.go new file mode 100644 index 0000000..429ed5f --- /dev/null +++ b/cmd/yamlToJson.go @@ -0,0 +1,52 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "fmt" + "io/ioutil" + "log" + "os" + + "github.com/marianina8/cli/utils" + "github.com/spf13/cobra" +) + +// yamlToJsonCmd represents the yamlToJson command +var yamlToJsonCmd = &cobra.Command{ + Use: "yamlToJson", + Short: "Converts yaml to json", + Aliases: []string{"y2j"}, + Run: func(cmd *cobra.Command, args []string) { + file := cmd.Flag("file").Value.String() + silence, _ := cmd.Flags().GetBool("silence") + output := cmd.Flag("output").Value.String() + + if file == "" { + fmt.Println("Please provide a YAML file to convert") + return + } + jsonData, err := utils.Y2Jtransform(file) + if err != nil { + log.Fatalf("Error converting YAML to JSON: %v", err) + os.Exit(1) + } + + if !silence { + fmt.Println(string(jsonData)) + } + + if output != "" { + err = ioutil.WriteFile(output, jsonData, 0644) + if err != nil { + log.Fatalf("Error writing JSON file: %v", err) + os.Exit(1) + } + } + }, +} + +func init() { + convertCmd.AddCommand(yamlToJsonCmd) +} diff --git a/dist/artifacts.json b/dist/artifacts.json new file mode 100644 index 0000000..19ae2ec --- /dev/null +++ b/dist/artifacts.json @@ -0,0 +1 @@ +[{"name":"workshop.exe","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_windows_amd64_v1/workshop.exe","goos":"windows","goarch":"amd64","goamd64":"v1","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":".exe","ID":"workshop"}},{"name":"workshop","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_darwin_amd64_v1/workshop","goos":"darwin","goarch":"amd64","goamd64":"v1","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":"","ID":"workshop"}},{"name":"workshop","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_linux_amd64_v1/workshop","goos":"linux","goarch":"amd64","goamd64":"v1","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":"","ID":"workshop"}},{"name":"workshop","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_linux_386/workshop","goos":"linux","goarch":"386","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":"","ID":"workshop"}},{"name":"workshop","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_linux_arm64/workshop","goos":"linux","goarch":"arm64","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":"","ID":"workshop"}},{"name":"workshop","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_darwin_arm64/workshop","goos":"darwin","goarch":"arm64","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":"","ID":"workshop"}},{"name":"workshop.exe","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_windows_386/workshop.exe","goos":"windows","goarch":"386","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":".exe","ID":"workshop"}},{"name":"workshop.exe","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_windows_arm64/workshop.exe","goos":"windows","goarch":"arm64","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":".exe","ID":"workshop"}},{"name":"workshop_Windows_i386.zip","path":"dist/workshop_Windows_i386.zip","goos":"windows","goarch":"386","internal_type":1,"type":"Archive","extra":{"Binaries":["workshop.exe"],"Builds":[{"name":"workshop.exe","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_windows_386/workshop.exe","goos":"windows","goarch":"386","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":".exe","ID":"workshop"}}],"Checksum":"sha256:e30d4e987e0f356687528e10d732053cc63b15055a6e4ad732fda954175c017b","Format":"tar.gz","ID":"default","Replaces":null,"WrappedIn":""}},{"name":"workshop_Linux_i386.tar.gz","path":"dist/workshop_Linux_i386.tar.gz","goos":"linux","goarch":"386","internal_type":1,"type":"Archive","extra":{"Binaries":["workshop"],"Builds":[{"name":"workshop","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_linux_386/workshop","goos":"linux","goarch":"386","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":"","ID":"workshop"}}],"Checksum":"sha256:b1c1d29828e0dc33b9e4ae0a943de36ac0b1a0d056c9ab52eaa3ebbdf9e7ae9e","Format":"tar.gz","ID":"default","Replaces":null,"WrappedIn":""}},{"name":"workshop_Windows_arm64.zip","path":"dist/workshop_Windows_arm64.zip","goos":"windows","goarch":"arm64","internal_type":1,"type":"Archive","extra":{"Binaries":["workshop.exe"],"Builds":[{"name":"workshop.exe","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_windows_arm64/workshop.exe","goos":"windows","goarch":"arm64","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":".exe","ID":"workshop"}}],"Checksum":"sha256:15a4c9334c870e867069b9d87a097d8a50a3adbcbe1392a268114a7b325bf324","Format":"tar.gz","ID":"default","Replaces":null,"WrappedIn":""}},{"name":"workshop_Linux_arm64.tar.gz","path":"dist/workshop_Linux_arm64.tar.gz","goos":"linux","goarch":"arm64","internal_type":1,"type":"Archive","extra":{"Binaries":["workshop"],"Builds":[{"name":"workshop","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_linux_arm64/workshop","goos":"linux","goarch":"arm64","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":"","ID":"workshop"}}],"Checksum":"sha256:5ec9347ab3272020a04876be535db43193dd20862cc7c30a88101d28454368cd","Format":"tar.gz","ID":"default","Replaces":null,"WrappedIn":""}},{"name":"workshop_Darwin_arm64.tar.gz","path":"dist/workshop_Darwin_arm64.tar.gz","goos":"darwin","goarch":"arm64","internal_type":1,"type":"Archive","extra":{"Binaries":["workshop"],"Builds":[{"name":"workshop","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_darwin_arm64/workshop","goos":"darwin","goarch":"arm64","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":"","ID":"workshop"}}],"Checksum":"sha256:73f2e87b3b694ff4e668e6aaa8ef66e300369c4f2b1145d76012d76f5ea0daa5","Format":"tar.gz","ID":"default","Replaces":null,"WrappedIn":""}},{"name":"workshop_Windows_x86_64.zip","path":"dist/workshop_Windows_x86_64.zip","goos":"windows","goarch":"amd64","goamd64":"v1","internal_type":1,"type":"Archive","extra":{"Binaries":["workshop.exe"],"Builds":[{"name":"workshop.exe","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_windows_amd64_v1/workshop.exe","goos":"windows","goarch":"amd64","goamd64":"v1","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":".exe","ID":"workshop"}}],"Checksum":"sha256:fa77fe8f3c5ca14d71686bacc5616e89415dd53737802d0e5e6cf588d72d0654","Format":"tar.gz","ID":"default","Replaces":null,"WrappedIn":""}},{"name":"workshop_Linux_x86_64.tar.gz","path":"dist/workshop_Linux_x86_64.tar.gz","goos":"linux","goarch":"amd64","goamd64":"v1","internal_type":1,"type":"Archive","extra":{"Binaries":["workshop"],"Builds":[{"name":"workshop","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_linux_amd64_v1/workshop","goos":"linux","goarch":"amd64","goamd64":"v1","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":"","ID":"workshop"}}],"Checksum":"sha256:7c40e7abd299c0c6d4bc60af119a4590396a82b7d74180f62635d0f9780d25dd","Format":"tar.gz","ID":"default","Replaces":null,"WrappedIn":""}},{"name":"workshop_Darwin_x86_64.tar.gz","path":"dist/workshop_Darwin_x86_64.tar.gz","goos":"darwin","goarch":"amd64","goamd64":"v1","internal_type":1,"type":"Archive","extra":{"Binaries":["workshop"],"Builds":[{"name":"workshop","path":"/Users/mmontagnino/Code/src/github.com/marianina8/workshop/session4/examples/example30/dist/workshop_darwin_amd64_v1/workshop","goos":"darwin","goarch":"amd64","goamd64":"v1","internal_type":4,"type":"Binary","extra":{"Binary":"workshop","Ext":"","ID":"workshop"}}],"Checksum":"sha256:d773abd0e52d74e158054f3eb133ef3e7ca1a846459d29918fef81b46ad69f5d","Format":"tar.gz","ID":"default","Replaces":null,"WrappedIn":""}},{"name":"checksums.txt","path":"dist/checksums.txt","internal_type":12,"type":"Checksum","extra":{}}] \ No newline at end of file diff --git a/dist/checksums.txt b/dist/checksums.txt new file mode 100644 index 0000000..c4cf0f6 --- /dev/null +++ b/dist/checksums.txt @@ -0,0 +1,8 @@ +15a4c9334c870e867069b9d87a097d8a50a3adbcbe1392a268114a7b325bf324 workshop_Windows_arm64.zip +5ec9347ab3272020a04876be535db43193dd20862cc7c30a88101d28454368cd workshop_Linux_arm64.tar.gz +73f2e87b3b694ff4e668e6aaa8ef66e300369c4f2b1145d76012d76f5ea0daa5 workshop_Darwin_arm64.tar.gz +7c40e7abd299c0c6d4bc60af119a4590396a82b7d74180f62635d0f9780d25dd workshop_Linux_x86_64.tar.gz +b1c1d29828e0dc33b9e4ae0a943de36ac0b1a0d056c9ab52eaa3ebbdf9e7ae9e workshop_Linux_i386.tar.gz +d773abd0e52d74e158054f3eb133ef3e7ca1a846459d29918fef81b46ad69f5d workshop_Darwin_x86_64.tar.gz +e30d4e987e0f356687528e10d732053cc63b15055a6e4ad732fda954175c017b workshop_Windows_i386.zip +fa77fe8f3c5ca14d71686bacc5616e89415dd53737802d0e5e6cf588d72d0654 workshop_Windows_x86_64.zip diff --git a/dist/config.yaml b/dist/config.yaml new file mode 100644 index 0000000..a78aee6 --- /dev/null +++ b/dist/config.yaml @@ -0,0 +1,129 @@ +project_name: workshop +release: + github: + owner: marianina8 + name: workshop + name_template: '{{.Tag}}' +scoop: + name: workshop + commit_author: + name: goreleaserbot + email: bot@goreleaser.com + commit_msg_template: Scoop update for {{ .ProjectName }} version {{ .Tag }} + goamd64: v1 +builds: + - id: workshop + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + - "386" + goarm: + - "6" + gomips: + - hardfloat + goamd64: + - v1 + targets: + - linux_amd64_v1 + - linux_arm64 + - linux_386 + - windows_amd64_v1 + - windows_arm64 + - windows_386 + - darwin_amd64_v1 + - darwin_arm64 + dir: . + main: . + binary: workshop + builder: go + gobinary: go + command: build + ldflags: + - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser + env: + - CGO_ENABLED=0 +archives: + - id: default + name_template: '{{ .ProjectName }}_ {{- title .Os }}_ {{- if eq .Arch "amd64" }}x86_64 {{- else if eq .Arch "386" }}i386 {{- else }}{{ .Arch }}{{ end }} {{- if .Arm }}v{{ .Arm }}{{ end }}' + format: tar.gz + format_overrides: + - goos: windows + format: zip + files: + - src: license* + - src: LICENSE* + - src: readme* + - src: README* + - src: changelog* + - src: CHANGELOG* +snapshot: + name_template: '{{ incpatch .Version }}-next' +checksum: + name_template: checksums.txt + algorithm: sha256 +changelog: + filters: + exclude: + - '^docs:' + - '^test:' + sort: asc +dist: dist +env_files: + github_token: ~/.config/goreleaser/github_token + gitlab_token: ~/.config/goreleaser/gitlab_token + gitea_token: ~/.config/goreleaser/gitea_token +before: + hooks: + - go mod tidy + - go generate ./... +source: + name_template: '{{ .ProjectName }}-{{ .Version }}' + format: tar.gz +gomod: + gobinary: go +announce: + twitter: + message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}' + mastodon: + message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}' + server: "" + reddit: + title_template: '{{ .ProjectName }} {{ .Tag }} is out!' + url_template: '{{ .ReleaseURL }}' + slack: + message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}' + username: GoReleaser + discord: + message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}' + author: GoReleaser + color: "3888754" + icon_url: https://goreleaser.com/static/avatar.png + teams: + title_template: '{{ .ProjectName }} {{ .Tag }} is out!' + message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}' + color: '#2D313E' + icon_url: https://goreleaser.com/static/avatar.png + smtp: + subject_template: '{{ .ProjectName }} {{ .Tag }} is out!' + body_template: 'You can view details from: {{ .ReleaseURL }}' + mattermost: + message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}' + title_template: '{{ .ProjectName }} {{ .Tag }} is out!' + username: GoReleaser + linkedin: + message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}' + telegram: + message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}' + webhook: + message_template: '{ "message": "{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}"}' + content_type: application/json; charset=utf-8 +git: + tag_sort: -version:refname +github_urls: + download: https://github.com +gitlab_urls: + download: https://gitlab.com diff --git a/dist/metadata.json b/dist/metadata.json new file mode 100644 index 0000000..828a50a --- /dev/null +++ b/dist/metadata.json @@ -0,0 +1 @@ +{"project_name":"workshop","tag":"v0.0.0","previous_tag":"","version":"0.0.1-next","commit":"8d8a27926ba09c4f98bb8d9ce5f9db7ea9a84706","date":"2023-06-16T17:42:03.877043-07:00","runtime":{"goos":"darwin","goarch":"arm64"}} \ No newline at end of file diff --git a/dist/workshop_Darwin_arm64.tar.gz b/dist/workshop_Darwin_arm64.tar.gz new file mode 100644 index 0000000..22188a0 Binary files /dev/null and b/dist/workshop_Darwin_arm64.tar.gz differ diff --git a/dist/workshop_Darwin_x86_64.tar.gz b/dist/workshop_Darwin_x86_64.tar.gz new file mode 100644 index 0000000..edbf7dc Binary files /dev/null and b/dist/workshop_Darwin_x86_64.tar.gz differ diff --git a/dist/workshop_Linux_arm64.tar.gz b/dist/workshop_Linux_arm64.tar.gz new file mode 100644 index 0000000..83faedc Binary files /dev/null and b/dist/workshop_Linux_arm64.tar.gz differ diff --git a/dist/workshop_Linux_i386.tar.gz b/dist/workshop_Linux_i386.tar.gz new file mode 100644 index 0000000..7e2d792 Binary files /dev/null and b/dist/workshop_Linux_i386.tar.gz differ diff --git a/dist/workshop_Linux_x86_64.tar.gz b/dist/workshop_Linux_x86_64.tar.gz new file mode 100644 index 0000000..11f4fe0 Binary files /dev/null and b/dist/workshop_Linux_x86_64.tar.gz differ diff --git a/dist/workshop_Windows_arm64.zip b/dist/workshop_Windows_arm64.zip new file mode 100644 index 0000000..c489a92 Binary files /dev/null and b/dist/workshop_Windows_arm64.zip differ diff --git a/dist/workshop_Windows_i386.zip b/dist/workshop_Windows_i386.zip new file mode 100644 index 0000000..32aac89 Binary files /dev/null and b/dist/workshop_Windows_i386.zip differ diff --git a/dist/workshop_Windows_x86_64.zip b/dist/workshop_Windows_x86_64.zip new file mode 100644 index 0000000..fc2a0c0 Binary files /dev/null and b/dist/workshop_Windows_x86_64.zip differ diff --git a/dist/workshop_darwin_amd64_v1/workshop b/dist/workshop_darwin_amd64_v1/workshop new file mode 100755 index 0000000..645559c Binary files /dev/null and b/dist/workshop_darwin_amd64_v1/workshop differ diff --git a/dist/workshop_darwin_arm64/workshop b/dist/workshop_darwin_arm64/workshop new file mode 100755 index 0000000..3e1af6c Binary files /dev/null and b/dist/workshop_darwin_arm64/workshop differ diff --git a/dist/workshop_linux_386/workshop b/dist/workshop_linux_386/workshop new file mode 100755 index 0000000..d6130bb Binary files /dev/null and b/dist/workshop_linux_386/workshop differ diff --git a/dist/workshop_linux_amd64_v1/workshop b/dist/workshop_linux_amd64_v1/workshop new file mode 100755 index 0000000..ac9cbc9 Binary files /dev/null and b/dist/workshop_linux_amd64_v1/workshop differ diff --git a/dist/workshop_linux_arm64/workshop b/dist/workshop_linux_arm64/workshop new file mode 100755 index 0000000..f88fb2d Binary files /dev/null and b/dist/workshop_linux_arm64/workshop differ diff --git a/dist/workshop_windows_386/workshop.exe b/dist/workshop_windows_386/workshop.exe new file mode 100755 index 0000000..5fe85e6 Binary files /dev/null and b/dist/workshop_windows_386/workshop.exe differ diff --git a/dist/workshop_windows_amd64_v1/workshop.exe b/dist/workshop_windows_amd64_v1/workshop.exe new file mode 100755 index 0000000..64b716c Binary files /dev/null and b/dist/workshop_windows_amd64_v1/workshop.exe differ diff --git a/dist/workshop_windows_arm64/workshop.exe b/dist/workshop_windows_arm64/workshop.exe new file mode 100755 index 0000000..22c39ed Binary files /dev/null and b/dist/workshop_windows_arm64/workshop.exe differ diff --git a/docker b/docker new file mode 100644 index 0000000..e69de29 diff --git a/docs/cli-convert-jsonToYaml.1 b/docs/cli-convert-jsonToYaml.1 new file mode 100644 index 0000000..068d05e --- /dev/null +++ b/docs/cli-convert-jsonToYaml.1 @@ -0,0 +1,46 @@ +.nh +.TH "JSON to YAML converter" "1" "May 2023" "Auto generated by marianina8" "" + +.SH NAME +.PP +cli-convert-jsonToYaml - Converts json to yaml + + +.SH SYNOPSIS +.PP +\fBcli convert jsonToYaml [flags]\fP + + +.SH DESCRIPTION +.PP +Converts json to yaml + + +.SH OPTIONS +.PP +\fB-h\fP, \fB--help\fP[=false] + help for jsonToYaml + + +.SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-f\fP, \fB--file\fP="" + JSON file to convert + +.PP +\fB-o\fP, \fB--output\fP="" + Output file name + +.PP +\fB-s\fP, \fB--silence\fP[=false] + Silence the output + + +.SH SEE ALSO +.PP +\fBcli-convert(1)\fP + + +.SH HISTORY +.PP +27-May-2023 Auto generated by spf13/cobra diff --git a/docs/cli-convert-yamlToJson.1 b/docs/cli-convert-yamlToJson.1 new file mode 100644 index 0000000..39f33de --- /dev/null +++ b/docs/cli-convert-yamlToJson.1 @@ -0,0 +1,46 @@ +.nh +.TH "JSON to YAML converter" "1" "May 2023" "Auto generated by marianina8" "" + +.SH NAME +.PP +cli-convert-yamlToJson - Converts yaml to json + + +.SH SYNOPSIS +.PP +\fBcli convert yamlToJson [flags]\fP + + +.SH DESCRIPTION +.PP +Converts yaml to json + + +.SH OPTIONS +.PP +\fB-h\fP, \fB--help\fP[=false] + help for yamlToJson + + +.SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-f\fP, \fB--file\fP="" + JSON file to convert + +.PP +\fB-o\fP, \fB--output\fP="" + Output file name + +.PP +\fB-s\fP, \fB--silence\fP[=false] + Silence the output + + +.SH SEE ALSO +.PP +\fBcli-convert(1)\fP + + +.SH HISTORY +.PP +27-May-2023 Auto generated by spf13/cobra diff --git a/docs/cli-convert.1 b/docs/cli-convert.1 new file mode 100644 index 0000000..edf6738 --- /dev/null +++ b/docs/cli-convert.1 @@ -0,0 +1,44 @@ +.nh +.TH "JSON to YAML converter" "1" "May 2023" "Auto generated by marianina8" "" + +.SH NAME +.PP +cli-convert - Converts a JSON to YAML file + + +.SH SYNOPSIS +.PP +\fBcli convert [flags]\fP + + +.SH DESCRIPTION +.PP +Converts a JSON to YAML file + + +.SH OPTIONS +.PP +\fB-f\fP, \fB--file\fP="" + JSON file to convert + +.PP +\fB-h\fP, \fB--help\fP[=false] + help for convert + +.PP +\fB-o\fP, \fB--output\fP="" + Output file name + +.PP +\fB-s\fP, \fB--silence\fP[=false] + Silence the output + + +.SH SEE ALSO +.PP +\fBcli(1)\fP, \fBcli-convert-jsonToYaml(1)\fP, \fBcli-convert-yamlToJson(1)\fP + + +.SH HISTORY +.PP +27-May-2023 Auto generated by spf13/cobra diff --git a/docs/cli.1 b/docs/cli.1 new file mode 100644 index 0000000..fe9b343 --- /dev/null +++ b/docs/cli.1 @@ -0,0 +1,42 @@ +.nh +.TH "JSON to YAML converter" "1" "May 2023" "Auto generated by marianina8" "" + +.SH NAME +.PP +cli - A brief description of your application + + +.SH SYNOPSIS +.PP +\fBcli [flags]\fP + + +.SH DESCRIPTION +.PP +A longer description that spans multiple lines and likely contains +examples and usage of using your application. For example: + +.PP +Cobra is a CLI library for Go that empowers applications. +This application is a tool to generate the needed files +to quickly create a Cobra application. + + +.SH OPTIONS +.PP +\fB-h\fP, \fB--help\fP[=false] + help for cli + +.PP +\fB-t\fP, \fB--toggle\fP[=false] + Help message for toggle + + +.SH SEE ALSO +.PP +\fBcli-convert(1)\fP + + +.SH HISTORY +.PP +27-May-2023 Auto generated by spf13/cobra diff --git a/documentation/main.go b/documentation/main.go new file mode 100644 index 0000000..0aa27fc --- /dev/null +++ b/documentation/main.go @@ -0,0 +1,19 @@ +package main + +import ( + "log" + + "github.com/marianina8/cli/cmd" + "github.com/spf13/cobra/doc" +) + +func main() { + header := &doc.GenManHeader{ + Title: "JSON to YAML converter", + Source: "Auto generated by marianina8", + } + err := doc.GenManTree(cmd.RootCmd(), header, "./docs") + if err != nil { + log.Fatal(err) + } +} diff --git a/example.json b/example.json new file mode 100644 index 0000000..bf9a6a0 --- /dev/null +++ b/example.json @@ -0,0 +1,13 @@ +{ + "title": "Building Modern CLI Applications with Go", + "instructors": [ + { + "name": "Marian Montagnino", + "email": "mmontagnino@netflix.com" + }, + { + "name": "Romeric Philogene", + "email": "rphiologene@qovery.com" + } + ] +} \ No newline at end of file diff --git a/example.txt b/example.txt new file mode 100644 index 0000000..36bb823 --- /dev/null +++ b/example.txt @@ -0,0 +1,10 @@ +1: Lorem ipsum dolor sit amet, consectetur adipiscing elit. +2: Sed in leo vestibulum, viverra libero eu, facilisis velit. +3: Fusce faucibus nibh sed turpis sagittis bibendum. +4: Integer luctus leo vel libero molestie, vitae consequat turpis venenatis. +5: Quisque et tortor rutrum, lobortis arcu in, congue metus. +6: Praesent dapibus sapien id nibh suscipit, at commodo quam suscipit. +7: Nullam ullamcorper lorem eu sapien interdum, non posuere ipsum euismod. +8: Pellentesque vel mauris nec turpis ultrices auctor. +9: Curabitur gravida justo vel lacinia tempus. +10: Donec commodo sapien vitae justo finibus sagittis. \ No newline at end of file diff --git a/example.yaml b/example.yaml new file mode 100644 index 0000000..605a894 --- /dev/null +++ b/example.yaml @@ -0,0 +1,6 @@ +title: Building Modern CLI Applications with Go +instructors: +- name: Marian Montagnino + email: mmontagnino@netflix.com +- name: Romeric Philogene + email: rphiologene@qovery.com \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3cffc7b --- /dev/null +++ b/go.mod @@ -0,0 +1,31 @@ +module github.com/marianina8/cli + +go 1.19 + +require github.com/AlecAivazis/survey/v2 v2.3.6 + +require ( + github.com/gdamore/encoding v1.0.0 // indirect + github.com/gdamore/tcell/v2 v2.5.4 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-runewidth v0.0.14 // indirect + github.com/rivo/uniseg v0.2.0 // indirect +) + +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect + github.com/mattn/go-colorable v0.1.2 // indirect + github.com/mattn/go-isatty v0.0.8 // indirect + github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect + github.com/mum4k/termdash v0.18.0 + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/spf13/cobra v1.7.0 + github.com/spf13/pflag v1.0.5 // indirect + golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect + golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect + golang.org/x/text v0.5.0 // indirect + gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b875a43 --- /dev/null +++ b/go.sum @@ -0,0 +1,85 @@ +github.com/AlecAivazis/survey/v2 v2.3.6 h1:NvTuVHISgTHEHeBFqt6BHOe4Ny/NwGZr7w+F8S9ziyw= +github.com/AlecAivazis/survey/v2 v2.3.6/go.mod h1:4AuI9b7RjAR+G7v9+C4YSlX/YL3K3cWNXgWXOhllqvI= +github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= +github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI= +github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= +github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= +github.com/gdamore/tcell/v2 v2.5.4 h1:TGU4tSjD3sCL788vFNeJnTdzpNKIw1H5dgLnJRQVv/k= +github.com/gdamore/tcell/v2 v2.5.4/go.mod h1:dZgRy5v4iMobMEcWNYBtREnDZAT9DYmfqIkrgEMxLyw= +github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog= +github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= +github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= +github.com/mum4k/termdash v0.18.0 h1:wpy3FKcVV5s2TOoMTKzqQXwL5VClZIlNrRqZDpeIzBA= +github.com/mum4k/termdash v0.18.0/go.mod h1:VWL18wLZDKVKF/f4TkMRiKZb9Eg8Ax99PtNuGuRAguw= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +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/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/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-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/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-20220422013727-9388b58f7150/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 h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/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-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 h1:CBpWXWQpIRjzmkkA+M7q9Fqnwd2mZr3AFqexg8YTfoM= +golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/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.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= +golang.org/x/text v0.5.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.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/goreleaser.yaml b/goreleaser.yaml new file mode 100644 index 0000000..8aa4659 --- /dev/null +++ b/goreleaser.yaml @@ -0,0 +1,51 @@ +before: + hooks: + - go mod tidy +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + +archives: + - format: tar.gz + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' +release: + prerelease: auto + +universal_binaries: + - replace: true +brews: + - + name: cli + homepage: https://github.com/marianina8 + tap: + owner: marianina8 + name: homebrew-cli + commit_author: + name: marianina8 \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..22b5e67 --- /dev/null +++ b/main.go @@ -0,0 +1,12 @@ +/* +Copyright © 2023 NAME HERE +*/ +package main + +import ( + "github.com/marianina8/cli/cmd" +) + +func main() { + cmd.Execute() +} diff --git a/models/models.go b/models/models.go new file mode 100644 index 0000000..dd72071 --- /dev/null +++ b/models/models.go @@ -0,0 +1,11 @@ +package models + +type Instructor struct { + Name string `json:"name"` + Email string `json:"email"` +} + +type Workshop struct { + Title string `json:"title"` + Instructors []Instructor `json:"instructors"` +} diff --git a/utils/transform.go b/utils/transform.go new file mode 100644 index 0000000..187a5a4 --- /dev/null +++ b/utils/transform.go @@ -0,0 +1,62 @@ +package utils + +import ( + "encoding/json" + "io/ioutil" + "os" + + "github.com/marianina8/cli/models" + "gopkg.in/yaml.v2" +) + +func J2Ytransform(filename string) ([]byte, error) { + file, err := os.Open(filename) + if err != nil { + return nil, err + } + defer file.Close() + + bytes, err := ioutil.ReadAll(file) + if err != nil { + return nil, err + } + + var jsonData models.Workshop + err = json.Unmarshal(bytes, &jsonData) + if err != nil { + return nil, err + } + + yamlData, err := yaml.Marshal(&jsonData) + if err != nil { + return nil, err + } + + return yamlData, nil +} + +func Y2Jtransform(filename string) ([]byte, error) { + file, err := os.Open(filename) + if err != nil { + return nil, err + } + defer file.Close() + + bytes, err := ioutil.ReadAll(file) + if err != nil { + return nil, err + } + + var yamlData models.Workshop + err = yaml.Unmarshal(bytes, &yamlData) + if err != nil { + return nil, err + } + + jsonData, err := json.Marshal(&yamlData) + if err != nil { + return nil, err + } + + return jsonData, nil +}