Skip to content

Commit

Permalink
Merge pull request #2 from tlkamp/version
Browse files Browse the repository at this point in the history
feat: add version command
  • Loading branch information
tlkamp authored Oct 1, 2023
2 parents eaa901a + 4a7906c commit d38553f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
with:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.PAT }}
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ changelog:
- '^docs:'
- '^test:'
- '^style:'
release:
github:
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,36 @@
A CLI for the Litter Robot 3.

## Usage
<details>
<summary>Basic</summary>

```console
$ litterrobot
Control your Litter Robot 3 Connect

Usage:
litterrobot [command]

Available Commands:
completion Generate the autocompletion script for the specified shell
config Manage local configuration for the CLI
help Help about any command
version print the version information

Flags:
-h, --help help for litterrobot

Use "litterrobot [command] --help" for more information about a command.
```
```

</details>

<details>
<summary>Version</summary>

```console
$ litterrobot version
$TAG - $COMMIT - $DATE
```

</details>

10 changes: 7 additions & 3 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
lrc "github.com/tlkamp/litter-api/v2/pkg/client"
)

func newLitterRobotCmd(c *lrc.Client) *cobra.Command {
func newLitterRobotCmd(c *lrc.Client, version string) *cobra.Command {
cmd := &cobra.Command{
Use: "litterrobot",
Short: "Control your Litter Robot 3 Connect",
Expand All @@ -29,10 +29,14 @@ func newLitterRobotCmd(c *lrc.Client) *cobra.Command {
},
}

cmd.AddCommand(
newVersionCmd(version),
)

return cmd
}

func Execute() error {
func Execute(v string) error {
var client *lrc.Client
return newLitterRobotCmd(client).Execute()
return newLitterRobotCmd(client, v).Execute()
}
13 changes: 13 additions & 0 deletions internal/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cmd

import "github.com/spf13/cobra"

func newVersionCmd(version string) *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "print the version information",
Run: func(c *cobra.Command, _ []string) {
c.Println(version)
},
}
}
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package main

import (
"fmt"

"github.com/tlkamp/litterrobot/internal/cmd"
)

var (
version = "dev"
commit = "none"
date = "unknown"
)

func main() {
cmd.Execute() //nolint:errcheck
versionString := fmt.Sprintf("%s - %s - %s", version, commit, date)
cmd.Execute(versionString) //nolint:errcheck
}

0 comments on commit d38553f

Please sign in to comment.