Skip to content

Commit

Permalink
feat: rework cobra commands to support annotations (#614)
Browse files Browse the repository at this point in the history
Signed-off-by: Engin Diri <[email protected]>
  • Loading branch information
Engin Diri authored Aug 27, 2022
1 parent c376012 commit 5a4f7a1
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 25 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ mincetl create \
--filename server-do.yaml
Flags:
-f, --filename string Contains the configuration for minectl
-f, --filename string Location of the manifest file
-h, --help help for create
-w, --wait Wait for Minecraft Server is started (default true)
Expand All @@ -652,7 +652,7 @@ mincetl delete \
Flags:
-f, --filename string that contains the configuration for minectl
-f, --filename string Location of the manifest file
-h, --help help for delete
--id string contains the server id
Expand Down Expand Up @@ -705,7 +705,7 @@ mincetl update \
--id xxx-xxx-xxx-xxx
Flags:
-f, --filename string Contains the configuration for minectl
-f, --filename string Location of the manifest file
-h, --help help for update
--id string contains the server id
Expand Down Expand Up @@ -733,7 +733,7 @@ mincetl rcon \
--id xxxx
Flags:
-f, --filename string Contains the configuration for minectl
-f, --filename string Location of the manifest file
-h, --help help for rcon
--id string contains the server id
```
Expand All @@ -759,11 +759,11 @@ mincetl plugins \
--destination /minecraft/mods
Flags:
-d, --destination string Plugin destination location
-f, --filename string Contains the configuration for minectl
-d, --destination string Plugin destination folder
-f, --filename string Location of the manifest file
-h, --help help for plugins
--id string contains the server id
-p, --plugin string Local plugin file location
-p, --plugin string Location of the plugin
Global Flags:
--headless Set this value to if mincetl is called by a CI system. Enables logging and disables human-readable output rendering (default: false)
Expand Down
7 changes: 4 additions & 3 deletions cmd/minectl/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
)

func init() {
createCmd.Flags().StringP("filename", "f", "", "Contains the configuration for minectl")
createCmd.Flags().StringP("filename", "f", "", "Location of the manifest file")
createCmd.Flags().SetAnnotation("filename", cobra.BashCompFilenameExt, []string{"yaml"}) //nolint:errcheck
createCmd.Flags().BoolP("wait", "w", true, "Wait for Minecraft Server is started")
}

Expand All @@ -29,10 +30,10 @@ var createCmd = &cobra.Command{
func runCreate(cmd *cobra.Command, _ []string) error {
filename, err := cmd.Flags().GetString("filename")
if len(filename) == 0 {
return errors.New("Please provide a valid MinecraftResource manifest file via -f|--filename flag")
return errors.New("Please provide a valid manifest file via -f|--filename flag")
}
if err != nil {
return errors.Wrap(err, "Please provide a valid MinecraftResource manifest file")
return errors.Wrap(err, "Please provide a valid manifest file")
}
p, err := provisioner.NewProvisioner(&provisioner.MinectlProvisionerOpts{
ManifestPath: filename,
Expand Down
5 changes: 3 additions & 2 deletions cmd/minectl/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

func init() {
deleteCmd.Flags().StringP("filename", "f", "", "that contains the configuration for minectl")
deleteCmd.Flags().StringP("filename", "f", "", "Location of the manifest file")
deleteCmd.Flags().SetAnnotation("filename", cobra.BashCompFilenameExt, []string{"yaml"}) //nolint:errcheck
deleteCmd.Flags().String("id", "", "contains the server id")
}

Expand All @@ -29,7 +30,7 @@ func runDelete(cmd *cobra.Command, _ []string) error {
return errors.Wrap(err, "failed to get 'filename' value")
}
if len(filename) == 0 {
return errors.New("Please provide a valid MinecraftResource manifest file via -f|--filename flag")
return errors.New("Please provide a valid manifest file via -f|--filename flag")
}
id, err := cmd.Flags().GetString("id")
if err != nil {
Expand Down
13 changes: 8 additions & 5 deletions cmd/minectl/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import (
)

func init() {
pluginCmd.Flags().StringP("filename", "f", "", "Contains the configuration for minectl")
pluginCmd.Flags().StringP("filename", "f", "", "Location of the manifest file")
pluginCmd.Flags().SetAnnotation("filename", cobra.BashCompFilenameExt, []string{"yaml"}) //nolint:errcheck
pluginCmd.Flags().String("id", "", "contains the server id")
pluginCmd.Flags().StringP("plugin", "p", "", "Local plugin file location")
pluginCmd.Flags().StringP("destination", "d", "", "Plugin destination location")
pluginCmd.Flags().StringP("plugin", "p", "", "Location of the plugin")
pluginCmd.Flags().SetAnnotation("plugin", cobra.BashCompFilenameExt, []string{"jar"}) //nolint:errcheck
pluginCmd.Flags().StringP("destination", "d", "", "Plugin destination folder")
pluginCmd.Flags().SetAnnotation("destination", cobra.BashCompSubdirsInDir, []string{}) //nolint:errcheck
}

type ModType string
Expand Down Expand Up @@ -54,10 +57,10 @@ var _ = []Plugin{
func runPlugin(cmd *cobra.Command, _ []string) error {
filename, err := cmd.Flags().GetString("filename")
if err != nil {
return errors.Wrap(err, "Please provide a valid MinecraftResource manifest file")
return errors.Wrap(err, "Please provide a valid manifest file")
}
if len(filename) == 0 {
return errors.New("Please provide a valid MinecraftResource manifest file via -f|--filename flag")
return errors.New("Please provide a valid manifest file via -f|--filename flag")
}
id, err := cmd.Flags().GetString("id")
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/minectl/rcon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

func init() {
rconCmd.Flags().StringP("filename", "f", "", "Contains the configuration for minectl")
rconCmd.Flags().StringP("filename", "f", "", "Location of the manifest file")
rconCmd.Flags().SetAnnotation("filename", cobra.BashCompFilenameExt, []string{"yaml"}) //nolint:errcheck
rconCmd.Flags().String("id", "", "contains the server id")
}

Expand All @@ -25,10 +26,10 @@ var rconCmd = &cobra.Command{
func runRCON(cmd *cobra.Command, _ []string) error {
filename, err := cmd.Flags().GetString("filename")
if len(filename) == 0 {
return errors.New("Please provide a valid MinecraftResource manifest file via -f|--filename flag")
return errors.New("Please provide a valid manifest file via -f|--filename flag")
}
if err != nil {
return errors.Wrap(err, "Please provide a valid MinecraftResource manifest file")
return errors.Wrap(err, "Please provide a valid manifest file")
}
id, err := cmd.Flags().GetString("id")
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/minectl/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

func init() {
updateCmd.Flags().StringP("filename", "f", "", "Contains the configuration for minectl")
updateCmd.Flags().StringP("filename", "f", "", "Location of the manifest file")
updateCmd.Flags().SetAnnotation("filename", cobra.BashCompFilenameExt, []string{"yaml"}) //nolint:errcheck
updateCmd.Flags().String("id", "", "contains the server id")
}

Expand All @@ -25,10 +26,10 @@ var updateCmd = &cobra.Command{
func runUpdate(cmd *cobra.Command, _ []string) error {
filename, err := cmd.Flags().GetString("filename")
if len(filename) == 0 {
return errors.New("Please provide a valid MinecraftResource manifest file")
return errors.New("Please provide a valid manifest file")
}
if err != nil {
return errors.Wrap(err, "Please provide a valid MinecraftResource manifest file via -f|--filename flag")
return errors.Wrap(err, "Please provide a valid manifest file via -f|--filename flag")
}
id, err := cmd.Flags().GetString("id")
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/minectl/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ var wizardCmd = &cobra.Command{
}

func init() {
usage := fmt.Sprintf("output folder for the configuration file for minectl 🗺 (default: %s)", GetHomeFolder())
wizardCmd.Flags().StringP("output", "o", "", usage)
wizardCmd.Flags().StringP("output", "o", "", "output folder for the configuration file for minectl 🗺 (default: ~/.minectl)")
wizardCmd.Flags().SetAnnotation("output", cobra.BashCompSubdirsInDir, []string{}) //nolint:errcheck
}

func runWizard(cmd *cobra.Command, _ []string) error {
Expand Down

0 comments on commit 5a4f7a1

Please sign in to comment.