{"id":15866398,"url":"https://github.com/squidmin/gocli","last_synced_at":"2025-04-01T21:20:40.888Z","repository":{"id":211028677,"uuid":"728020336","full_name":"squidmin/gocli","owner":"squidmin","description":"Command-Line Interface (CLI) template built with Go, leveraging the Cobra library","archived":false,"fork":false,"pushed_at":"2024-03-14T01:23:22.000Z","size":4830,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T13:54:17.628Z","etag":null,"topics":["cli","cobra","cobra-cli","go","golang","template","template-project"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/squidmin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-06T03:55:58.000Z","updated_at":"2024-03-14T01:21:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"6ccb7fb6-4b76-44f7-872d-8ce656e448f7","html_url":"https://github.com/squidmin/gocli","commit_stats":null,"previous_names":["squidmin/gocli"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squidmin%2Fgocli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squidmin%2Fgocli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squidmin%2Fgocli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squidmin%2Fgocli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/squidmin","download_url":"https://codeload.github.com/squidmin/gocli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246709985,"owners_count":20821314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","cobra","cobra-cli","go","golang","template","template-project"],"created_at":"2024-10-05T23:20:34.806Z","updated_at":"2025-04-01T21:20:40.866Z","avatar_url":"https://github.com/squidmin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gocli\n\n`gocli` is a simple Command-Line Interface (CLI) application built with Go, leveraging the Cobra library for easy command management.\nIt is a template and should be treated as a starting point for building your own CLI applications.\n\nIn this document you can find instructions for building, running, and extending `gocli`.\n\n## Prerequisites\n\n- Go 1.16 or later\n- A code editor or IDE\n- Basic knowledge of Go and the command line\n\n## Installation\n\nClone the repository:\n\n```shell\ngit clone\n```\n\nNavigate to the project directory:\n\n```shell\ncd gocli\n```\n\n## Project Structure\n\nThe project structure is as follows:\n\n```\n├── cmd\n│   └── cli\n│       └── main.go\n├── go.mod\n├── go.sum\n└── README.md\n```\n\n- `cmd/cli/main.go`: The main entry point for the application.\n- `go.mod` and `go.sum`: Go module files that define the module's dependencies.\n- `README.md`: The project documentation.\n\n## Building the Application\n\nTo compile the `gocli` application and generate an executable file, follow these steps:\n\n1. Navigate to the `cmd/cli` directory:\n   ```shell\n   cd cmd/cli\n   ```\n\n   This compiles your program and generates an executable file.\n\n2. Build the application:\n   ```shell\n   go build -o gocli\n   ```\n\n   This creates an executable file named `gocli` in the same directory.\n\n   A build script (`build.sh`) is also provided for convenience. You can run it using the following command:\n   ```shell\n   ./build.sh\n   ```\n\n   This process compiles the program into an executable named gocli in the current directory.\n\n## Running the Application\n\n```shell\nchmod +x gocli\n./gocli\n```\n\nUpon successful execution, you will see the application's output, indicating that `gocli` is running properly.\n\n## Extending the Application\n\n### Adding new commands\n\nThe `gocli` application can be easily extended with additional commands using the Cobra library.\nBelow is an example of how to add a `version` command to your CLI application:\n\n1. **Define the `version` command**: \\\n   Add the following code to your `main.go` or an appropriate file within the `cmd/cli` directory:\n   ```go\n   package main\n\n   import (\n\t   \"fmt\"\n\t   \"github.com/spf13/cobra\"\n   )\n\n   func main() {\n\t   // Define the version command\n\t   var versionCmd = \u0026cobra.Command{\n\t\t   Use:   \"version\",\n\t\t   Short: \"Prints the version of gocli\",\n\t\t   Run: func(cmd *cobra.Command, args []string) {\n\t\t\t   fmt.Println(\"gocli version 1.0.0\")\n\t\t   },\n\t   }\n   }\n   ```\n2. **Add the `version` command to the root command**: \\\n   Add the following code to the `main` function in `main.go`:\n   ```go\n   func main() {\n       // Define the root command\n       var rootCmd = \u0026cobra.Command{Use: \"gocli\"}\n\n       // Add the version command to the root command\n       rootCmd.AddCommand(versionCmd)\n\n       // Execute the root command\n       if err := rootCmd.Execute(); err != nil {\n           fmt.Println(err)\n           os.Exit(1)\n       }\n   }\n   ```\n3. **Rebuild the application**: \\\n   After adding the new command, rebuild the application using the build steps mentioned earlier.\n4. **Run the `version` command**: \\\n   After rebuilding the application, you can run the `version` command by executing the following command:\n   ```shell\n   ./gocli version\n   ```\n   You should see the output: `gocli version 1.0.0`, indicating that the `version` command is functioning correctly.\n\n---\n\n## Conclusion\n\nThis documentation provides the essential steps to build, run, and extend the `gocli` application.\nWith the Cobra library, adding more commands and functionality to your CLI tool is straightforward, allowing for scalable and maintainable command-line applications.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquidmin%2Fgocli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquidmin%2Fgocli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquidmin%2Fgocli/lists"}