This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
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.
This commit adds the `prm set backend` command and some minor refactoring of existing set command functionality and the `config` package.
- Loading branch information
sanfrancrisko
committed
Nov 30, 2021
1 parent
387f13d
commit 37daa52
Showing
5 changed files
with
113 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package set | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/puppetlabs/prm/pkg/prm" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var SelectedBackend prm.BackendType | ||
|
||
func (sc *SetCommand) createSetBackendCommand() *cobra.Command { | ||
tmp := &cobra.Command{ | ||
Use: "backend <BACKEND>", | ||
Short: "Sets the backend exec environment to the specified type", | ||
Long: `Sets the backend exec environment to the specified type`, | ||
PreRunE: sc.setBackendPreRunE, | ||
RunE: sc.setBackendType, | ||
ValidArgs: []string{string(prm.DOCKER)}, | ||
} | ||
|
||
return tmp | ||
} | ||
|
||
func (sc *SetCommand) setBackendPreRunE(cmd *cobra.Command, args []string) (err error) { | ||
if len(args) > 1 { | ||
return fmt.Errorf("too many args, please specify ONE of the following backend types after 'set backend':\n- %s", prm.DOCKER) | ||
} | ||
|
||
if len(args) < 1 { | ||
return fmt.Errorf("please specify specify one of the following backend types after 'set backend':\n- %s", prm.DOCKER) | ||
} | ||
|
||
switch strings.ToLower(args[0]) { | ||
case string(prm.DOCKER): | ||
SelectedBackend = prm.DOCKER | ||
default: | ||
return fmt.Errorf("'%s' is not a valid backend type, please specify one of the following backend types:\n- %s", args[0], prm.DOCKER) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (sc *SetCommand) setBackendType(cmd *cobra.Command, args []string) error { | ||
return sc.Utils.SetAndWriteConfig(prm.BackendCfgKey, string(SelectedBackend)) | ||
} |
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