diff --git a/AGENTS.md b/AGENTS.md index 2e0aace..6ffe232 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1 +1,15 @@ # Dear Agent + +This is a CLI tool for the Honeycomb.io API, written in Go. + +## Structure + +- `main.go` - entry point +- `cmd/` - cobra command definitions (root, version, etc.) +- `honeycomb/` - API client package + +## Install + +```shell +go install github.com/maragudk/honeycomb-cli@latest +``` diff --git a/README.md b/README.md index d9ced71..7abdf8f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,26 @@ -# template +# honeycomb-cli -[![Docs](https://pkg.go.dev/badge/maragu.dev/template)](https://pkg.go.dev/maragu.dev/template) -[![CI](https://github.com/maragudk/template/actions/workflows/ci.yml/badge.svg)](https://github.com/maragudk/template/actions/workflows/ci.yml) +[![CI](https://github.com/maragudk/honeycomb-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/maragudk/honeycomb-cli/actions/workflows/ci.yml) -Made with ✨sparkles✨ by [maragu](https://www.maragu.dev/): independent software consulting for cloud-native Go apps & AI engineering. +A command-line interface for the [Honeycomb.io](https://www.honeycomb.io/) observability platform. -[Contact me at markus@maragu.dk](mailto:markus@maragu.dk) for consulting work, or perhaps an invoice to support this project? +Made with sparkles by [maragu](https://www.maragu.dev/). + +## Install + +```shell +go install github.com/maragudk/honeycomb-cli@latest +``` + +## Usage + +```shell +# Set your API key +export HONEYCOMB_API_KEY=your-api-key + +# Or pass it as a flag +honeycomb-cli --api-key your-api-key + +# Verify your API key +honeycomb-cli auth +``` diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..c00166b --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,49 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +var rootCmd = &cobra.Command{ + Use: "honeycomb-cli", + Short: "A CLI for the Honeycomb.io API", + Long: "A command-line interface for interacting with the Honeycomb.io observability platform.", +} + +// Execute the root command and return an exit code. +func Execute() int { + if err := rootCmd.Execute(); err != nil { + fmt.Fprintln(os.Stderr, err) + return 1 + } + return 0 +} + +func init() { + rootCmd.PersistentFlags().String("api-key", "", "Honeycomb API key (or set HONEYCOMB_API_KEY)") + rootCmd.PersistentFlags().String("api-url", "https://api.honeycomb.io", "Honeycomb API URL (or set HONEYCOMB_API_URL)") +} + +// apiKey returns the API key from the flag or environment variable. +func apiKey(cmd *cobra.Command) string { + key, _ := cmd.Flags().GetString("api-key") + if key != "" { + return key + } + return os.Getenv("HONEYCOMB_API_KEY") +} + +// apiURL returns the API URL from the flag or environment variable. +func apiURL(cmd *cobra.Command) string { + url, _ := cmd.Flags().GetString("api-url") + if url != "https://api.honeycomb.io" { + return url + } + if envURL := os.Getenv("HONEYCOMB_API_URL"); envURL != "" { + return envURL + } + return url +} diff --git a/cmd/root_test.go b/cmd/root_test.go new file mode 100644 index 0000000..5c7b0cd --- /dev/null +++ b/cmd/root_test.go @@ -0,0 +1,16 @@ +package cmd_test + +import ( + "testing" + + "maragu.dev/is" + + "github.com/maragudk/honeycomb-cli/cmd" +) + +func TestExecute(t *testing.T) { + t.Run("returns 0 on success", func(t *testing.T) { + code := cmd.Execute() + is.Equal(t, 0, code) + }) +} diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..2eb6361 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,20 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// version is set at build time via -ldflags. +var version = "dev" + +func init() { + rootCmd.AddCommand(&cobra.Command{ + Use: "version", + Short: "Print the version", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(version) + }, + }) +} diff --git a/go.mod b/go.mod index f52a35e..38a8e78 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,13 @@ -module maragu.dev/template +module github.com/maragudk/honeycomb-cli go 1.26 + +require ( + github.com/spf13/cobra v1.10.2 + maragu.dev/is v0.3.1 +) + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.9 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..bf67f6c --- /dev/null +++ b/go.sum @@ -0,0 +1,12 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= +github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= +github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +maragu.dev/is v0.3.1 h1:1sj4Ewc9Ecqtvp1Aro+kRCpnuu4D5CB8w//GOfM7jFs= +maragu.dev/is v0.3.1/go.mod h1:bviaM5S0fBshCw7wuumFGTju/izopZ/Yvq4g7Klc7y8= diff --git a/main.go b/main.go new file mode 100644 index 0000000..e345bdb --- /dev/null +++ b/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "os" + + "github.com/maragudk/honeycomb-cli/cmd" +) + +func main() { + os.Exit(cmd.Execute()) +} diff --git a/template.go b/template.go deleted file mode 100644 index 38cdfe4..0000000 --- a/template.go +++ /dev/null @@ -1 +0,0 @@ -package template