From f64abcee325ead7cc13406208d9f308b4f75dc06 Mon Sep 17 00:00:00 2001 From: Kristoffer Risa Date: Sat, 31 Jan 2026 20:03:34 +0100 Subject: [PATCH 1/2] added version feature --- Makefile | 9 +++++++-- internal/commands/version.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 internal/commands/version.go diff --git a/Makefile b/Makefile index 48cfe8b..3a9df93 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,16 @@ BINARY=powerctl # Build directory DIST=dist -# Version (from git tag or commit) +# Version info VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") +GIT_COMMIT=$(shell git rev-parse HEAD 2>/dev/null || echo "unknown") +BUILD_DATE=$(shell date -u +%Y-%m-%dT%H:%M:%SZ) # Build flags -LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION)" +LDFLAGS=-ldflags "-s -w \ + -X github.com/kristofferrisa/powerctl-cli/internal/commands.Version=$(VERSION) \ + -X github.com/kristofferrisa/powerctl-cli/internal/commands.GitCommit=$(GIT_COMMIT) \ + -X github.com/kristofferrisa/powerctl-cli/internal/commands.BuildDate=$(BUILD_DATE)" # Default target build: diff --git a/internal/commands/version.go b/internal/commands/version.go new file mode 100644 index 0000000..96c017c --- /dev/null +++ b/internal/commands/version.go @@ -0,0 +1,32 @@ +package commands + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var ( + // Version is the current version of powerctl-cli + // This can be overridden at build time using -ldflags + Version = "dev" + // GitCommit is the git commit hash (set at build time) + GitCommit = "unknown" + // BuildDate is when the binary was built (set at build time) + BuildDate = "unknown" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print version information", + Long: `Display the current version, git commit, and build date of powerctl-cli.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("powerctl-cli version %s\n", Version) + fmt.Printf("Git commit: %s\n", GitCommit) + fmt.Printf("Built: %s\n", BuildDate) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} From 84c9209b4eec9d0f0e8d71992c9a2ef491aba690 Mon Sep 17 00:00:00 2001 From: Kristoffer Risa Date: Sat, 31 Jan 2026 20:08:18 +0100 Subject: [PATCH 2/2] updated documentation --- README.md | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1a50466..bcc307c 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,12 @@ make build 2. **Run setup wizard:** ```bash - tibber config init + powerctl config init ``` 3. **View your home:** ```bash - tibber home + powerctl home ``` ## Usage @@ -52,25 +52,35 @@ make build **Option 1: Environment variable (recommended)** ```bash export TIBBER_TOKEN="your-token-here" -tibber home +powerctl home ``` **Option 2: Config file** ```bash -tibber config init # Interactive setup +powerctl config init # Interactive setup # or manually edit ~/.tibber/config.yaml ``` **Option 3: Command flag** ```bash -tibber --config /path/to/config.yaml home +powerctl --config /path/to/config.yaml home ``` ### Commands +#### Check Version +```bash +powerctl version +``` +``` +powerctl-cli version 1.0.0 +Git commit: a1b2c3d +Built: 2026-01-31T10:30:00Z +``` + #### View Home Information ```bash -tibber home +powerctl home ``` ``` ⚡ My House @@ -91,7 +101,7 @@ tibber home #### Check Electricity Prices ```bash -tibber prices +powerctl prices ``` ``` ⚡ Electricity Prices @@ -107,7 +117,7 @@ tibber prices #### Stream Live Power Consumption ```bash -tibber live +powerctl live ``` ``` ⚡ Live Power @@ -132,12 +142,12 @@ Default output is beautiful colored CLI. Change format with `--format`: **JSON** (for scripting/piping): ```bash -tibber prices --format json | jq '.current.total' +powerctl prices --format json | jq '.current.total' ``` **Markdown** (for AI/documentation): ```bash -tibber home --format markdown +powerctl home --format markdown ``` ## Configuration File @@ -152,12 +162,12 @@ format: "pretty" # Options: pretty, json, markdown View current config: ```bash -tibber config show +powerctl config show ``` Update a value: ```bash -tibber config set format json +powerctl config set format json ``` ## Development @@ -190,7 +200,7 @@ make lint # Run linter (requires golangci-lint) ## Troubleshooting **"No API token found"** -- Set `TIBBER_TOKEN` environment variable or run `tibber config init` +- Set `TIBBER_TOKEN` environment variable or run `powerctl config init` **"Pulse not enabled"** - Ensure your Tibber Pulse is connected and active