Skip to content

Commit

Permalink
feat: add root command
Browse files Browse the repository at this point in the history
Adds the root command as an entry point for all commands to follow
  • Loading branch information
tlkamp committed Oct 1, 2023
1 parent 9363b69 commit f369cde
Show file tree
Hide file tree
Showing 8 changed files with 656 additions and 1 deletion.
57 changes: 57 additions & 0 deletions .github/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Test
on:
push:
tags-ignore:
- '**'
branches:
- '**'
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: 1.20
- name: Checkout code
uses: actions/checkout@v4
- name: Test
run: go test -v ./...

golangci-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: 1.20
- name: golangci-lint
uses: golangci/golangci-lint-action@v3

goreleaser-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: 1.20
- uses: goreleaser/goreleaser-action@v2
with:
args: check

release-dry-run:
runs-on: ubuntu-latest
needs:
- test
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- name: Release Dry Run
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx -p @semantic-release/changelog -p @semantic-release/git -p semantic-release \
semantic-release -d --branches ${GITHUB_REF##*/}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

# Go workspace file
go.work

litterrobot
9 changes: 9 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
branches:
- main
plugins:
- '@semantic-release/commit-analyzer'
- '@semantic-release/release-notes-generator'
- '@semantic-release/changelog'
- - '@semantic-release/git'
- message: "chore(release): ${nextRelease.version} \n\n${nextRelease.notes}"
- '@semantic-release/github'
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
# litterrobot
# litterrobot
A CLI for the Litter Robot 3.

## Usage
```console
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

Flags:
-h, --help help for litterrobot

Use "litterrobot [command] --help" for more information about a command.
```
29 changes: 29 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module github.com/tlkamp/litterrobot

go 1.20

require (
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
github.com/tlkamp/litter-api/v2 v2.1.0
)

require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
492 changes: 492 additions & 0 deletions go.sum

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cmd

import (
"os"
"path"

"github.com/spf13/cobra"
"github.com/spf13/viper"
lrc "github.com/tlkamp/litter-api/v2/pkg/client"
)

func newLitterRobotCmd(c *lrc.Client) *cobra.Command {
cmd := &cobra.Command{
Use: "litterrobot",
Short: "Control your Litter Robot 3 Connect",
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
dir, err := os.UserHomeDir()
if err != nil {
return err
}

configPath := path.Join(dir, ".litterrobot")

viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(configPath)
viper.ReadInConfig()
return nil
},
}

return cmd
}

func Execute() error {
var client *lrc.Client
return newLitterRobotCmd(client).Execute()
}
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

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

func main() {
cmd.Execute()
}

0 comments on commit f369cde

Please sign in to comment.