Commit e4ba706

Karn Wong <karn@karnwong.me>
2023-12-28 17:11:33
return key path
1 parent 930f5a7
Changed files (1)
cmd/ssh/ssh_create_ssh_key.go
@@ -8,6 +8,7 @@ import (
 	"fmt"
 	"log"
 	"os"
+	"path/filepath"
 
 	"golang.org/x/crypto/ssh"
 
@@ -34,6 +35,18 @@ func writeStringToFile(filePath, data string, permission os.FileMode) {
 	}
 }
 
+func returnKeyPath(fileName string) string {
+	currentDir, err := os.Getwd()
+	if err != nil {
+		fmt.Println("Error:", err)
+	}
+
+	keyPath := filepath.Join(currentDir, fileName)
+	keyPath = keyPath + ".pem"
+
+	return keyPath
+}
+
 // main
 func createSSHKeyEDSA(fileName string) {
 	// Generate a new Ed25519 private key
@@ -67,11 +80,17 @@ var createSSHKey = &cobra.Command{
 	Short: "Create SSH key",
 	Long:  `Create SSH key`,
 	Run: func(cmd *cobra.Command, args []string) {
+		//init
+		if len(args) == 0 {
+			fmt.Println("Please specify key name")
+			os.Exit(1)
+		}
+
+		// main
 		color.Green("SSH: create-ssh-key")
 
-		fileName := "foo"
-		createSSHKeyEDSA(fileName)
-		fmt.Printf("\tSSH key created at: %s\n", fileName)
+		createSSHKeyEDSA(args[0])
+		fmt.Printf("\tSSH key created at: %s\n", returnKeyPath(args[0]))
 	},
 }