Add copy to clipboard flag for ssh

This commit is contained in:
Bernd Schoolmann 2023-07-18 22:07:40 +02:00
parent c2e5801769
commit bb2c6bf963
No known key found for this signature in database
1 changed files with 6 additions and 2 deletions

View File

@ -29,6 +29,7 @@ var sshAddCmd = &cobra.Command{
The variables are stored as a secure note. Consult the documentation for more information.`,
Run: func(cmd *cobra.Command, args []string) {
name, _ := cmd.Flags().GetString("name")
copyToClipboard, _ := cmd.Flags().GetBool("clipboard")
result, err := client.SendToAgent(ipc.CreateSSHKeyRequest{
Name: name,
@ -43,7 +44,10 @@ var sshAddCmd = &cobra.Command{
case ipc.CreateSSHKeyResponse:
response := result.(ipc.CreateSSHKeyResponse)
fmt.Println(response.Digest)
clipboard.WriteAll(string(response.Digest))
if copyToClipboard {
clipboard.WriteAll(string(response.Digest))
}
break
case ipc.ActionResponse:
println("Error: " + result.(ipc.ActionResponse).Message)
@ -83,6 +87,6 @@ func init() {
sshCmd.AddCommand(sshAddCmd)
sshAddCmd.PersistentFlags().String("name", "", "")
sshAddCmd.MarkFlagRequired("name")
sshAddCmd.PersistentFlags().Bool("--clipboard", false, "Copy the public key to the clipboard")
sshAddCmd.PersistentFlags().Bool("clipboard", false, "Copy the public key to the clipboard")
sshCmd.AddCommand(listSSHCmd)
}