delete added, more details below (#3)
- readme updates - delete command added - commands now saved in a map vs fields - login and run now ensure config has been run to prevent errors Reviewed-on: #3 Co-authored-by: jake <jake.young.dev@gmail.com> Co-committed-by: jake <jake.young.dev@gmail.com>
This commit is contained in:
15
cmd/login.go
15
cmd/login.go
@@ -5,6 +5,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
@@ -15,9 +16,10 @@ import (
|
||||
|
||||
// loginCmd represents the login command
|
||||
var loginCmd = &cobra.Command{
|
||||
Use: "login",
|
||||
Example: "mctl login",
|
||||
Short: "Login to server and send commands",
|
||||
Use: "login",
|
||||
Example: "mctl login",
|
||||
SilenceUsage: true,
|
||||
Short: "Login to server and send commands",
|
||||
Long: `Login to server using saved config and enter command loop
|
||||
sending commands to server and printing the response.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
@@ -54,6 +56,13 @@ var loginCmd = &cobra.Command{
|
||||
|
||||
fmt.Printf("Disconnected from %s\n", server)
|
||||
},
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
//ensure config command has been run
|
||||
if viper.Get("server") == "" || viper.Get("password") == "" || viper.Get("port") == 0 {
|
||||
return errors.New("the 'config' command must be run before you can interact with servers")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
Reference in New Issue
Block a user