Skip to content

Commit

Permalink
Utilize the Taskfile some more. Add a version subcommand to kefw2.
Browse files Browse the repository at this point in the history
  • Loading branch information
hilli committed May 23, 2023
1 parent d223f88 commit 29e0c9b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
kef-virtual-hub
bin
.task
14 changes: 12 additions & 2 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is a Taskfile. See https://taskfile.dev
# `brew install go-task` to install task runner
# `brew install go-task` to install task runner or `go install github.com/go-task/task/v3/cmd/task@latest`
# `task --list` to list all tasks
# `task <taskname>` to run a task

Expand All @@ -8,13 +8,23 @@ version: '3'
tasks:
setup:
desc: Install dependencies
run: once
cmds:
- brew install vhs

build:
desc: Build binaries
cmds:
- go build -o bin/kefw2 cmd/kefw2/kefw2.go
- go build -ldflags="-X github.com/hilli/go-kef-w2/cmd.Version={{.GIT_COMMIT}}" -o bin/kefw2 cmd/kefw2/kefw2.go
alias: [b]
sources:
- cmd/kefw2/**/*.go
- kefw2/*.go
generates:
- bin/kefw2
vars:
GIT_COMMIT:
sh: git log -n 1 --format=%h

includes:
docs:
Expand Down
11 changes: 10 additions & 1 deletion cmd/kefw2/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
speakers []kefw2.KEFSpeaker
defaultSpeaker *kefw2.KEFSpeaker
currentSpeaker *kefw2.KEFSpeaker
Version string
)

// rootCmd represents the base command when called without any subcommands
Expand All @@ -50,6 +51,14 @@ var rootCmd = &cobra.Command{
// Run: func(cmd *cobra.Command, args []string) { },
}

var VersionCmd = &cobra.Command{
Use: "version",
Long: "Print the version number of kefw2",
Run: func(cmd *cobra.Command, args []string) {
log.Info("kefw2 version: ", Version)
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
Expand All @@ -60,7 +69,7 @@ func Execute() {
}

func init() {
rootCmd.AddCommand(ConfigCmd)
rootCmd.AddCommand(ConfigCmd, VersionCmd)
cobra.OnInitialize(initConfig)

// Find home directory.
Expand Down
8 changes: 6 additions & 2 deletions docs/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
version: '3'
tasks:
record:
desc: Record kefw2.tape actions to docs/kefw2.gif (requires vhs)
desc: Record kefw2.tape actions to docs/kefw2.gif (requires vhs, Music.app and JXA)
platforms: [darwin]
cmds:
- rm -f ~/.config/kefw2/kefw2.yaml
- vhs kefw2.tape
- vhs kefw2.tape
preconditions:
- test -f ../bin/kefw2
- which vhs

0 comments on commit 29e0c9b

Please sign in to comment.