-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_key.go
43 lines (36 loc) · 937 Bytes
/
create_key.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package cmd
import (
"os"
"github.com/lasthyphen/subnet-cli/internal/key"
"github.com/lasthyphen/subnet-cli/pkg/color"
"github.com/spf13/cobra"
)
func newCreateKeyCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "key [options]",
Short: "Generates a private key",
Long: `
Generates a private key.
$ subnet-cli create key --private-key-path=.insecure.test.key
`,
RunE: createKeyFunc,
}
return cmd
}
func createKeyFunc(cmd *cobra.Command, args []string) error {
if _, err := os.Stat(privKeyPath); err == nil {
color.Outf("{{red}}key already found at %q{{/}}\n", privKeyPath)
return os.ErrExist
}
k, err := key.NewSoft(0)
if err != nil {
return err
}
if err := k.Save(privKeyPath); err != nil {
return err
}
color.Outf("{{green}}created a new key %q{{/}}\n", privKeyPath)
return nil
}