Add
function takes hostname
this allows the use of cobra flags to configure the hostname.
This commit is contained in:
parent
20df6c559c
commit
b748ebd619
7
add.go
7
add.go
@ -187,17 +187,16 @@ func GetWGPeerTemplate(peerConfType PeerConfType, peer *PeerConfig, conf *DsnetC
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add prompts for the required information and creates a new peer
|
// Add prompts for the required information and creates a new peer
|
||||||
func Add() {
|
func Add(hostname string) {
|
||||||
if len(os.Args) != 3 {
|
if hostname == "" {
|
||||||
// TODO non-red
|
// TODO non-red
|
||||||
ExitFail("Hostname argument required: dsnet add <hostname>")
|
ExitFail("Hostname required: dsnet add --hostname <hostname>")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO maybe accept flags to avoid prompt and allow programmatic use?
|
// TODO maybe accept flags to avoid prompt and allow programmatic use?
|
||||||
// TODO accept existing pubkey
|
// TODO accept existing pubkey
|
||||||
conf := MustLoadDsnetConfig()
|
conf := MustLoadDsnetConfig()
|
||||||
|
|
||||||
hostname := os.Args[2]
|
|
||||||
owner := MustPromptString("owner", true)
|
owner := MustPromptString("owner", true)
|
||||||
description := MustPromptString("Description", true)
|
description := MustPromptString("Description", true)
|
||||||
// publicKey := MustPromptString("PublicKey (optional)", false)
|
// publicKey := MustPromptString("PublicKey (optional)", false)
|
||||||
|
10
cmd/dsnet.go
10
cmd/dsnet.go
@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// Flags.
|
// Flags.
|
||||||
outputType string
|
hostname string
|
||||||
|
|
||||||
// Commands.
|
// Commands.
|
||||||
rootCmd = &cobra.Command{}
|
rootCmd = &cobra.Command{}
|
||||||
@ -30,7 +30,7 @@ var (
|
|||||||
|
|
||||||
addCmd = &cobra.Command{
|
addCmd = &cobra.Command{
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
dsnet.Add()
|
dsnet.Add(hostname)
|
||||||
},
|
},
|
||||||
Use: "add",
|
Use: "add",
|
||||||
Short: "Add a new peer + sync",
|
Short: "Add a new peer + sync",
|
||||||
@ -86,8 +86,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rootCmd.PersistentFlags().String("output", "wg-quick", "config file format: vyatta/wg-quick/nixos")
|
// Flags.
|
||||||
|
rootCmd.PersistentFlags().StringP("output", "o", "wg-quick", "config file format: vyatta/wg-quick/nixos")
|
||||||
|
addCmd.Flags().StringVarP(&hostname, "hostname", "n", "", "hostname of new peer")
|
||||||
|
|
||||||
|
// Environment variable handling.
|
||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
viper.SetEnvPrefix("DSNET")
|
viper.SetEnvPrefix("DSNET")
|
||||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||||
@ -96,6 +99,7 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adds subcommands.
|
||||||
rootCmd.AddCommand(initCmd)
|
rootCmd.AddCommand(initCmd)
|
||||||
rootCmd.AddCommand(addCmd)
|
rootCmd.AddCommand(addCmd)
|
||||||
rootCmd.AddCommand(upCmd)
|
rootCmd.AddCommand(upCmd)
|
||||||
|
Loading…
Reference in New Issue
Block a user