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
|
||||
func Add() {
|
||||
if len(os.Args) != 3 {
|
||||
func Add(hostname string) {
|
||||
if hostname == "" {
|
||||
// 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 accept existing pubkey
|
||||
conf := MustLoadDsnetConfig()
|
||||
|
||||
hostname := os.Args[2]
|
||||
owner := MustPromptString("owner", true)
|
||||
description := MustPromptString("Description", true)
|
||||
// publicKey := MustPromptString("PublicKey (optional)", false)
|
||||
|
10
cmd/dsnet.go
10
cmd/dsnet.go
@ -12,7 +12,7 @@ import (
|
||||
|
||||
var (
|
||||
// Flags.
|
||||
outputType string
|
||||
hostname string
|
||||
|
||||
// Commands.
|
||||
rootCmd = &cobra.Command{}
|
||||
@ -30,7 +30,7 @@ var (
|
||||
|
||||
addCmd = &cobra.Command{
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
dsnet.Add()
|
||||
dsnet.Add(hostname)
|
||||
},
|
||||
Use: "add",
|
||||
Short: "Add a new peer + sync",
|
||||
@ -86,8 +86,11 @@ var (
|
||||
)
|
||||
|
||||
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.SetEnvPrefix("DSNET")
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
@ -96,6 +99,7 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Adds subcommands.
|
||||
rootCmd.AddCommand(initCmd)
|
||||
rootCmd.AddCommand(addCmd)
|
||||
rootCmd.AddCommand(upCmd)
|
||||
|
Loading…
Reference in New Issue
Block a user