Skip to content

Commit

Permalink
Adds option to add alias of the configured server in the configure co…
Browse files Browse the repository at this point in the history
…mmand

Signed-off-by: Saahil Bhavsar <saahil_bhavsar@outlook.com>
  • Loading branch information
SaahilNotSahil committed Jul 25, 2024
1 parent c105c6a commit 54cbab5
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cli/cmd/configure.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package cmd

import (
"bufio"
"fmt"
"log"
"os"
"os/exec"
"runtime"
"strings"

"github.com/devlup-labs/spok/cli/cmd/alias"
"github.com/devlup-labs/spok/internal/pkg"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -208,6 +210,38 @@ var configureCmd = &cobra.Command{
}

fmt.Println("Configured SPoK server for:", emailArgs)

userInput := "y"

fmt.Print("Would you like to add an alias for this server now? [Y/n]: ")
fmt.Scanln(&userInput)

if strings.ToLower(userInput) == "n" {
os.Exit(0)
} else {
var aliasName string
var value string
var description string

value = fmt.Sprintf("ssh %s", userArgs)

fmt.Print("Enter an alias for this server: ")
fmt.Scanln(&aliasName)

fmt.Print("Provide a short description for the alias (Press ENTER to leave blank): ")
reader := bufio.NewReader(os.Stdin)
description, err = reader.ReadString('\n')
cobra.CheckErr(err)
description = description[:len(description)-1]

aliases := new(alias.Aliases)
cobra.CheckErr(aliases.ReadFromFile())

aliases.Add(aliasName, value, description)
cobra.CheckErr(aliases.WriteToFile())

fmt.Printf("Successfully added the alias to the file: %s\n", alias.AliasFilePath)
}
},
}

Expand Down

0 comments on commit 54cbab5

Please sign in to comment.