-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added api command and edited config.go to be more extensible an…
…d usable by other files
- Loading branch information
Showing
2 changed files
with
78 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/Slug-Boi/aion-cli/forms" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// apiCmd represents the api command | ||
var apiCmd = &cobra.Command{ | ||
Use: "api <API_Key>", | ||
Short: "This sub command edits the API key in the config file.", | ||
Long: `This command allows you to edit the API key in the config file. | ||
The config file is located in the user's config directory. Example: ` + UserConf() + `config.json`, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("Reading current config file") | ||
|
||
conf, err := forms.GetConfigFile() | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
conf.Apikey = args[0] | ||
|
||
f, err := os.OpenFile(UserConf()+"config.json", os.O_RDWR, 0644) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
WriteConfig(f, conf) | ||
fmt.Println("API key updated") | ||
|
||
}, | ||
} | ||
|
||
func init() { | ||
configCmd.AddCommand(apiCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters