-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new command for account Update README.md
- Loading branch information
Showing
5 changed files
with
110 additions
and
2 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
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
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,76 @@ | ||
/* | ||
Copyright © 2022 Hai.Tran (github.com/epiHATR) | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"cloudflare/pkg/api/account" | ||
"cloudflare/pkg/consts/text" | ||
"cloudflare/pkg/model/response" | ||
"cloudflare/pkg/util/output" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var accountUpdateCmdAccountId string = "" | ||
var accountUpdateData string = "" | ||
var accountForceUpdate bool = false | ||
var accountUpdateConfirmText = "no" | ||
|
||
var accountUpdateCmd = &cobra.Command{ | ||
Use: "update", | ||
Short: "update a Cloudflare account/organization information", | ||
Long: text.AccountUpdateLongText + text.SubCmdHelpText, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
errText := []string{} | ||
if len(accountUpdateCmdAccountId) <= 0 { | ||
errText = append(errText, "--account-id") | ||
} | ||
if len(accountUpdateData) <= 0 { | ||
errText = append(errText, "--data|-d") | ||
} | ||
if len(errText) > 0 { | ||
fmt.Fprintln(os.Stderr, "Error: Missing mandatory inputs, following flags are required: ", strings.Join(errText, ", ")) | ||
fmt.Fprintln(os.Stderr, text.SubCmdHelpText) | ||
os.Exit(1) | ||
} | ||
|
||
log.Println("Updating account id", accountUpdateCmdAccountId) | ||
if !accountForceUpdate { | ||
for { | ||
fmt.Print("Please confirm your action (yes/no): ") | ||
fmt.Scan(&accountUpdateConfirmText) | ||
if strings.ToLower(accountUpdateConfirmText) == "yes" || strings.ToLower(accountUpdateConfirmText) == "no" { | ||
break | ||
} | ||
} | ||
} else { | ||
accountUpdateConfirmText = "yes" | ||
} | ||
|
||
if accountUpdateConfirmText == "yes" { | ||
res := account.UpdateAccount(accountUpdateCmdAccountId, accountUpdateData) | ||
|
||
if !res.Success { | ||
fmt.Fprintln(os.Stderr, "Error: failed to update account/organization. The error is", res.Errors[0].Message) | ||
os.Exit(1) | ||
} else { | ||
result := response.CmdResponse{} | ||
result.Success = res.Success | ||
output.PrintOut(result, flagQuery, flagOutput) | ||
} | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
accountCmd.AddCommand(accountUpdateCmd) | ||
accountUpdateCmd.Flags().StringVarP(&accountUpdateCmdAccountId, "account-id", "", "", "ID of Cloudflare account/organization") | ||
accountUpdateCmd.Flags().StringVarP(&accountUpdateData, "data", "d", "", "DNS id need to update") | ||
accountUpdateCmd.Flags().BoolVarP(&accountForceUpdate, "--force", "f", false, "force update DNS records without confirm") | ||
} |
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
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