@@ -16,28 +16,42 @@ func init() {
1616}
1717
1818type ConfigFile struct {
19- Key string `json:"key"`
19+ Key string `json:"key"`
20+ ApiEndpoint string `json:"apiEndpoint"`
2021}
2122
2223var initCmd = & cobra.Command {
2324 Use : "init" ,
2425 Short : "Initialize the CLI for use" ,
25- Long : "Initialize the CLI for use, including configuring the Warrant API key." ,
26+ Long : "Initialize the CLI for use, including configuring server endpoint and API key." ,
2627 Example : `
2728warrant init` ,
2829 Args : cobra .NoArgs ,
2930 RunE : func (cmd * cobra.Command , args []string ) error {
30- fmt .Println ("Please navigate to https://app .warrant.dev/account in your browser, login and retrieve your API key (prod or test) and enter it here :" )
31+ fmt .Println ("Warrant endpoint override (leave blank to use https://api .warrant.dev default) :" )
3132 fmt .Print ("> " )
3233 buf := bufio .NewReader (os .Stdin )
3334 input , err := buf .ReadBytes ('\n' )
3435 if err != nil {
3536 return err
3637 }
37- fmt .Println ("Creating ~/.warrant.json" )
38+ endpoint := strings .TrimSpace (string (input ))
39+ if endpoint == "" {
40+ endpoint = "https://api.warrant.dev"
41+ }
42+ fmt .Println ("API Key:" )
43+ fmt .Print ("> " )
44+ buf = bufio .NewReader (os .Stdin )
45+ input , err = buf .ReadBytes ('\n' )
46+ if err != nil {
47+ return err
48+ }
3849 key := strings .TrimSpace (string (input ))
50+
51+ fmt .Println ("Creating ~/.warrant.json" )
3952 config := ConfigFile {
40- Key : key ,
53+ ApiEndpoint : endpoint ,
54+ Key : key ,
4155 }
4256 fileContents , err := json .MarshalIndent (config , "" , " " )
4357 if err != nil {
0 commit comments