Skip to content

Commit

Permalink
chore: add support for --raw-input in schedule runs
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerinthenight committed Jun 1, 2023
1 parent 083a0d5 commit 0e285b3
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions cmds/cost/aws/calculations/schedule/schedule.go
Expand Up @@ -100,6 +100,7 @@ func ListCmd() *cobra.Command {

func CreateCmd() *cobra.Command {
var (
rawInput string
notifyChan string
dryrun bool
)
Expand Down Expand Up @@ -128,7 +129,7 @@ You can get the notification channel id by using the command:
ret = 1
}

if len(args) == 0 {
if len(args) == 0 && rawInput == "" {
fnerr(fmt.Errorf("id cannot be empty"))
return
}
Expand All @@ -147,15 +148,25 @@ You can get the notification channel id by using the command:
}

defer client.Close()
r := cost.CreateCalculationsScheduleRequest{
Vendor: "aws",
Schedule: args[0],
Force: true, // default at the moment
DryRun: dryrun,
}
var r cost.CreateCalculationsScheduleRequest
switch {
case rawInput != "":
err := json.Unmarshal([]byte(rawInput), &r)
if err != nil {
fnerr(err)
return
}
default:
r = cost.CreateCalculationsScheduleRequest{
Vendor: "aws",
Schedule: args[0],
Force: true, // default at the moment
DryRun: dryrun,
}

if notifyChan != "" {
r.NotificationChannel = notifyChan
if notifyChan != "" {
r.NotificationChannel = notifyChan
}
}

resp, err := client.CreateCalculationsSchedule(ctx, &r)
Expand All @@ -169,6 +180,7 @@ You can get the notification channel id by using the command:
}

cmd.Flags().SortFlags = false
cmd.Flags().StringVar(&rawInput, "raw-input", rawInput, "raw JSON input; see https://labs.alphaus.cloud/blueapidocs/#/Cost/Cost_CreateCalculationsSchedule")
cmd.Flags().StringVar(&notifyChan, "notification-channel", notifyChan, "notification channel id; if empty, creates a channel using your email")
cmd.Flags().BoolVar(&dryrun, "dryrun", dryrun, "if true, simulate notification only, no actual calculation")
return cmd
Expand Down

0 comments on commit 0e285b3

Please sign in to comment.