generated from rog-golang-buddies/golang-template-repository
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from rog-golang-buddies/whutchinson98/feat/sta…
…rter-commands feat: Set up basic commands that are called from cmd/main.go
- Loading branch information
Showing
6 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package commands | ||
|
||
type BaseCommand struct { | ||
Name string | ||
Description string | ||
Run func(commands *[]string, flags *map[string]interface{}) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package commands | ||
|
||
import "fmt" | ||
|
||
var HelpCommand = BaseCommand{ | ||
Name: "help", | ||
Description: "Provides list of all commands", | ||
Run: helpCommand, | ||
} | ||
|
||
func helpCommand(commands *[]string, flags *map[string]interface{}) error { | ||
// We have to "remake" the help command otherwise we get a runtime cycle error | ||
commandsList := []BaseCommand{{Name: "help", Description: "Provides list of all commands"}, VersionCommand} | ||
|
||
for _, command := range commandsList { | ||
fmt.Printf("[%v]: %v\n", command.Name, command.Description) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
) | ||
|
||
var VersionCommand = BaseCommand{ | ||
Name: "version", | ||
Description: "Provides useful information about go environment", | ||
Run: versionCommand, | ||
} | ||
|
||
func versionCommand(commands *[]string, flags *map[string]interface{}) error { | ||
fmt.Printf("Go Version: %v\n", runtime.Version()) | ||
fmt.Printf("GAA: %v\n", runtime.GOARCH) | ||
fmt.Printf("GOOS: %v\n", runtime.GOOS) | ||
return nil | ||
} |