Skip to content

Commit

Permalink
Add a command for printing all available gola commands
Browse files Browse the repository at this point in the history
  • Loading branch information
RashadAnsari committed Jul 11, 2021
1 parent 72eb014 commit a629293
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ export APP_VERSION=v0.0.0
export BUILD_INFO_PKG="github.com/RashadAnsari/gola/pkg/version"
export LDFLAGS="-w -s -X '$(BUILD_INFO_PKG).AppVersion=$(APP_VERSION)' -X '$(BUILD_INFO_PKG).Date=$$(date)' -X '$(BUILD_INFO_PKG).BuildVersion=$$(git rev-parse HEAD | cut -c 1-8)' -X '$(BUILD_INFO_PKG).VCSRef=$$(git rev-parse --abbrev-ref HEAD)'"

version:
@go run -ldflags $(LDFLAGS) ./cmd/gola version

binary:
@go build -ldflags $(LDFLAGS) ./cmd/gola

Expand Down
32 changes: 32 additions & 0 deletions internal/app/gola/cmd/commands/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package commands

import (
"github.com/spf13/cobra"

"github.com/RashadAnsari/gola/internal/app/gola/config"
"github.com/RashadAnsari/gola/internal/app/gola/log"
)

func main() {
cfg, err := config.Init()
if err != nil {
log.Fatal("Failed to load configuration.")
}

for _, command := range cfg.Commands {
log.Println(command.Name)
}
}

// Register registers commands command for gola binary.
func Register(root *cobra.Command) {
root.AddCommand(
&cobra.Command{
Use: "commands",
Short: "Print all available gola commands",
Run: func(_ *cobra.Command, args []string) {
main()
},
},
)
}
3 changes: 3 additions & 0 deletions internal/app/gola/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cmd
import (
"github.com/spf13/cobra"

"github.com/RashadAnsari/gola/internal/app/gola/cmd/commands"

"github.com/RashadAnsari/gola/internal/app/gola/cmd/run"

"github.com/RashadAnsari/gola/internal/app/gola/cmd/version"
Expand All @@ -23,6 +25,7 @@ func NewRootCommand() *cobra.Command {

version.Register(root)
run.Register(root)
commands.Register(root)

return root
}
File renamed without changes.

0 comments on commit a629293

Please sign in to comment.