[CLI] Fix init checks (#314)

* empty config check & version flag support

* fix: empty config check & version flag support (#309)

* fix

* cli init check
Prevent execution without initialization by checking cfgData and returning error if not initialized

* merge with master

* Replace errors.New with fmt.Errorf

Signed-off-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>

---------

Signed-off-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
This commit is contained in:
Dusan Sekulic
2024-09-17 15:42:09 +02:00
committed by GitHub
parent 0fe52386e8
commit 7a83f9957e
2 changed files with 25 additions and 33 deletions

View File

@@ -221,10 +221,6 @@ func config(ctx *cli.Context) error {
if err != nil {
return err
}
if cfgData == nil {
fmt.Println("no configuration found, run 'init' command")
return nil
}
cfg := map[string]interface{}{
"asp_url": cfgData.AspUrl,
@@ -388,6 +384,12 @@ func getArkSdkClient(ctx *cli.Context) (arksdk.ArkClient, error) {
if err != nil {
return nil, err
}
commandName := ctx.Args().First()
if commandName != "init" && cfgData == nil {
return nil, fmt.Errorf("CLI not initialized, run 'init' cmd to initialize")
}
net := getNetwork(ctx, cfgData)
if isBtcChain(net) {