fixed apps and dashboard command generation

This commit is contained in:
Andrew Nester 2024-11-08 13:36:48 +01:00
parent da4b856e57
commit 91ad4df7bf
No known key found for this signature in database
GPG Key ID: 12BC628A44B7DA57
4 changed files with 50 additions and 67 deletions

View File

@ -115,6 +115,9 @@ func new{{.PascalName}}() *cobra.Command {
{{- if .Request}} {{- if .Request}}
var {{.CamelName}}Req {{.Service.Package.Name}}.{{.Request.PascalName}} var {{.CamelName}}Req {{.Service.Package.Name}}.{{.Request.PascalName}}
{{- if .RequestBodyField }}
{{.CamelName}}Req.{{.RequestBodyField.PascalName}} = &{{.Service.Package.Name}}.{{.RequestBodyField.Entity.PascalName}}{}
{{- end }}
{{- if .CanUseJson}} {{- if .CanUseJson}}
var {{.CamelName}}Json flags.JsonFlag var {{.CamelName}}Json flags.JsonFlag
{{- end}} {{- end}}
@ -232,7 +235,7 @@ func new{{.PascalName}}() *cobra.Command {
{{- if .Request }} {{- if .Request }}
{{ if .CanUseJson }} {{ if .CanUseJson }}
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := {{.CamelName}}Json.Unmarshal(&{{.CamelName}}Req) diags := {{.CamelName}}Json.Unmarshal(&{{.CamelName}}Req{{ if .RequestBodyField }}.{{.RequestBodyField.PascalName}}{{ end }})
if diags.HasError() { if diags.HasError() {
return diags.Error() return diags.Error()
} }
@ -392,7 +395,7 @@ func new{{.PascalName}}() *cobra.Command {
if err != nil { if err != nil {
return fmt.Errorf("invalid {{$field.ConstantName}}: %s", args[{{$arg}}]) return fmt.Errorf("invalid {{$field.ConstantName}}: %s", args[{{$arg}}])
}{{else -}} }{{else -}}
{{$method.CamelName}}Req.{{$field.PascalName}} = args[{{$arg}}] {{$method.CamelName}}Req.{{ if $method.RequestBodyField }}{{$method.RequestBodyField.PascalName}}.{{end}}{{$field.PascalName}} = args[{{$arg}}]
{{- end -}} {{- end -}}
{{- if $optionalIfJsonIsUsed }} {{- if $optionalIfJsonIsUsed }}
} }

View File

@ -67,6 +67,7 @@ func newCreate() *cobra.Command {
cmd := &cobra.Command{} cmd := &cobra.Command{}
var createReq apps.CreateAppRequest var createReq apps.CreateAppRequest
createReq.App = &apps.App{}
var createJson flags.JsonFlag var createJson flags.JsonFlag
var createSkipWait bool var createSkipWait bool
@ -79,16 +80,20 @@ func newCreate() *cobra.Command {
// TODO: complex arg: app // TODO: complex arg: app
cmd.Use = "create" cmd.Use = "create NAME"
cmd.Short = `Create an app.` cmd.Short = `Create an app.`
cmd.Long = `Create an app. cmd.Long = `Create an app.
Creates a new app.` Creates a new app.
Arguments:
NAME: The name of the app. The name must contain only lowercase alphanumeric
characters and hyphens. It must be unique within the workspace.`
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(0) check := root.ExactArgs(1)
return check(cmd, args) return check(cmd, args)
} }
@ -98,7 +103,7 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) diags := createJson.Unmarshal(&createReq.App)
if diags.HasError() { if diags.HasError() {
return diags.Error() return diags.Error()
} }
@ -109,6 +114,9 @@ func newCreate() *cobra.Command {
} }
} }
} }
if !cmd.Flags().Changed("json") {
createReq.App.Name = args[0]
}
wait, err := w.Apps.Create(ctx, createReq) wait, err := w.Apps.Create(ctx, createReq)
if err != nil { if err != nil {
@ -219,6 +227,7 @@ func newDeploy() *cobra.Command {
cmd := &cobra.Command{} cmd := &cobra.Command{}
var deployReq apps.CreateAppDeploymentRequest var deployReq apps.CreateAppDeploymentRequest
deployReq.AppDeployment = &apps.AppDeployment{}
var deployJson flags.JsonFlag var deployJson flags.JsonFlag
var deploySkipWait bool var deploySkipWait bool
@ -231,19 +240,16 @@ func newDeploy() *cobra.Command {
// TODO: complex arg: app_deployment // TODO: complex arg: app_deployment
cmd.Use = "deploy APP_NAME" cmd.Use = "deploy"
cmd.Short = `Create an app deployment.` cmd.Short = `Create an app deployment.`
cmd.Long = `Create an app deployment. cmd.Long = `Create an app deployment.
Creates an app deployment for the app with the supplied name. Creates an app deployment for the app with the supplied name.`
Arguments:
APP_NAME: The name of the app.`
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(1) check := root.ExactArgs(0)
return check(cmd, args) return check(cmd, args)
} }
@ -253,7 +259,7 @@ func newDeploy() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := deployJson.Unmarshal(&deployReq) diags := deployJson.Unmarshal(&deployReq.AppDeployment)
if diags.HasError() { if diags.HasError() {
return diags.Error() return diags.Error()
} }
@ -264,7 +270,6 @@ func newDeploy() *cobra.Command {
} }
} }
} }
deployReq.AppName = args[0]
wait, err := w.Apps.Deploy(ctx, deployReq) wait, err := w.Apps.Deploy(ctx, deployReq)
if err != nil { if err != nil {
@ -903,6 +908,7 @@ func newUpdate() *cobra.Command {
cmd := &cobra.Command{} cmd := &cobra.Command{}
var updateReq apps.UpdateAppRequest var updateReq apps.UpdateAppRequest
updateReq.App = &apps.App{}
var updateJson flags.JsonFlag var updateJson flags.JsonFlag
// TODO: short flags // TODO: short flags
@ -917,7 +923,8 @@ func newUpdate() *cobra.Command {
Updates the app with the supplied name. Updates the app with the supplied name.
Arguments: Arguments:
NAME: The name of the app.` NAME: The name of the app. The name must contain only lowercase alphanumeric
characters and hyphens. It must be unique within the workspace.`
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
@ -932,7 +939,7 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) diags := updateJson.Unmarshal(&updateReq.App)
if diags.HasError() { if diags.HasError() {
return diags.Error() return diags.Error()
} }
@ -943,7 +950,9 @@ func newUpdate() *cobra.Command {
} }
} }
} }
updateReq.Name = args[0] if !cmd.Flags().Changed("json") {
updateReq.App.Name = args[0]
}
response, err := w.Apps.Update(ctx, updateReq) response, err := w.Apps.Update(ctx, updateReq)
if err != nil { if err != nil {

View File

@ -70,6 +70,7 @@ func newCreate() *cobra.Command {
cmd := &cobra.Command{} cmd := &cobra.Command{}
var createReq dashboards.CreateDashboardRequest var createReq dashboards.CreateDashboardRequest
createReq.Dashboard = &dashboards.Dashboard{}
var createJson flags.JsonFlag var createJson flags.JsonFlag
// TODO: short flags // TODO: short flags
@ -96,7 +97,7 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) diags := createJson.Unmarshal(&createReq.Dashboard)
if diags.HasError() { if diags.HasError() {
return diags.Error() return diags.Error()
} }
@ -140,6 +141,7 @@ func newCreateSchedule() *cobra.Command {
cmd := &cobra.Command{} cmd := &cobra.Command{}
var createScheduleReq dashboards.CreateScheduleRequest var createScheduleReq dashboards.CreateScheduleRequest
createScheduleReq.Schedule = &dashboards.Schedule{}
var createScheduleJson flags.JsonFlag var createScheduleJson flags.JsonFlag
// TODO: short flags // TODO: short flags
@ -147,30 +149,22 @@ func newCreateSchedule() *cobra.Command {
// TODO: complex arg: schedule // TODO: complex arg: schedule
cmd.Use = "create-schedule DASHBOARD_ID" cmd.Use = "create-schedule"
cmd.Short = `Create dashboard schedule.` cmd.Short = `Create dashboard schedule.`
cmd.Long = `Create dashboard schedule. cmd.Long = `Create dashboard schedule.`
Arguments:
DASHBOARD_ID: UUID identifying the dashboard to which the schedule belongs.`
// This command is being previewed; hide from help output. // This command is being previewed; hide from help output.
cmd.Hidden = true cmd.Hidden = true
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(1)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) { cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context() ctx := cmd.Context()
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createScheduleJson.Unmarshal(&createScheduleReq) diags := createScheduleJson.Unmarshal(&createScheduleReq.Schedule)
if diags.HasError() { if diags.HasError() {
return diags.Error() return diags.Error()
} }
@ -181,7 +175,6 @@ func newCreateSchedule() *cobra.Command {
} }
} }
} }
createScheduleReq.DashboardId = args[0]
response, err := w.Lakeview.CreateSchedule(ctx, createScheduleReq) response, err := w.Lakeview.CreateSchedule(ctx, createScheduleReq)
if err != nil { if err != nil {
@ -215,6 +208,7 @@ func newCreateSubscription() *cobra.Command {
cmd := &cobra.Command{} cmd := &cobra.Command{}
var createSubscriptionReq dashboards.CreateSubscriptionRequest var createSubscriptionReq dashboards.CreateSubscriptionRequest
createSubscriptionReq.Subscription = &dashboards.Subscription{}
var createSubscriptionJson flags.JsonFlag var createSubscriptionJson flags.JsonFlag
// TODO: short flags // TODO: short flags
@ -222,31 +216,22 @@ func newCreateSubscription() *cobra.Command {
// TODO: complex arg: subscription // TODO: complex arg: subscription
cmd.Use = "create-subscription DASHBOARD_ID SCHEDULE_ID" cmd.Use = "create-subscription"
cmd.Short = `Create schedule subscription.` cmd.Short = `Create schedule subscription.`
cmd.Long = `Create schedule subscription. cmd.Long = `Create schedule subscription.`
Arguments:
DASHBOARD_ID: UUID identifying the dashboard to which the subscription belongs.
SCHEDULE_ID: UUID identifying the schedule to which the subscription belongs.`
// This command is being previewed; hide from help output. // This command is being previewed; hide from help output.
cmd.Hidden = true cmd.Hidden = true
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(2)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) { cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context() ctx := cmd.Context()
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createSubscriptionJson.Unmarshal(&createSubscriptionReq) diags := createSubscriptionJson.Unmarshal(&createSubscriptionReq.Subscription)
if diags.HasError() { if diags.HasError() {
return diags.Error() return diags.Error()
} }
@ -257,8 +242,6 @@ func newCreateSubscription() *cobra.Command {
} }
} }
} }
createSubscriptionReq.DashboardId = args[0]
createSubscriptionReq.ScheduleId = args[1]
response, err := w.Lakeview.CreateSubscription(ctx, createSubscriptionReq) response, err := w.Lakeview.CreateSubscription(ctx, createSubscriptionReq)
if err != nil { if err != nil {
@ -1108,6 +1091,7 @@ func newUpdate() *cobra.Command {
cmd := &cobra.Command{} cmd := &cobra.Command{}
var updateReq dashboards.UpdateDashboardRequest var updateReq dashboards.UpdateDashboardRequest
updateReq.Dashboard = &dashboards.Dashboard{}
var updateJson flags.JsonFlag var updateJson flags.JsonFlag
// TODO: short flags // TODO: short flags
@ -1115,19 +1099,16 @@ func newUpdate() *cobra.Command {
// TODO: complex arg: dashboard // TODO: complex arg: dashboard
cmd.Use = "update DASHBOARD_ID" cmd.Use = "update"
cmd.Short = `Update dashboard.` cmd.Short = `Update dashboard.`
cmd.Long = `Update dashboard. cmd.Long = `Update dashboard.
Update a draft dashboard. Update a draft dashboard.`
Arguments:
DASHBOARD_ID: UUID identifying the dashboard.`
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error { cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(1) check := root.ExactArgs(0)
return check(cmd, args) return check(cmd, args)
} }
@ -1137,7 +1118,7 @@ func newUpdate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq) diags := updateJson.Unmarshal(&updateReq.Dashboard)
if diags.HasError() { if diags.HasError() {
return diags.Error() return diags.Error()
} }
@ -1148,7 +1129,6 @@ func newUpdate() *cobra.Command {
} }
} }
} }
updateReq.DashboardId = args[0]
response, err := w.Lakeview.Update(ctx, updateReq) response, err := w.Lakeview.Update(ctx, updateReq)
if err != nil { if err != nil {
@ -1182,6 +1162,7 @@ func newUpdateSchedule() *cobra.Command {
cmd := &cobra.Command{} cmd := &cobra.Command{}
var updateScheduleReq dashboards.UpdateScheduleRequest var updateScheduleReq dashboards.UpdateScheduleRequest
updateScheduleReq.Schedule = &dashboards.Schedule{}
var updateScheduleJson flags.JsonFlag var updateScheduleJson flags.JsonFlag
// TODO: short flags // TODO: short flags
@ -1189,31 +1170,22 @@ func newUpdateSchedule() *cobra.Command {
// TODO: complex arg: schedule // TODO: complex arg: schedule
cmd.Use = "update-schedule DASHBOARD_ID SCHEDULE_ID" cmd.Use = "update-schedule"
cmd.Short = `Update dashboard schedule.` cmd.Short = `Update dashboard schedule.`
cmd.Long = `Update dashboard schedule. cmd.Long = `Update dashboard schedule.`
Arguments:
DASHBOARD_ID: UUID identifying the dashboard to which the schedule belongs.
SCHEDULE_ID: UUID identifying the schedule.`
// This command is being previewed; hide from help output. // This command is being previewed; hide from help output.
cmd.Hidden = true cmd.Hidden = true
cmd.Annotations = make(map[string]string) cmd.Annotations = make(map[string]string)
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(2)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) { cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context() ctx := cmd.Context()
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := updateScheduleJson.Unmarshal(&updateScheduleReq) diags := updateScheduleJson.Unmarshal(&updateScheduleReq.Schedule)
if diags.HasError() { if diags.HasError() {
return diags.Error() return diags.Error()
} }
@ -1224,8 +1196,6 @@ func newUpdateSchedule() *cobra.Command {
} }
} }
} }
updateScheduleReq.DashboardId = args[0]
updateScheduleReq.ScheduleId = args[1]
response, err := w.Lakeview.UpdateSchedule(ctx, updateScheduleReq) response, err := w.Lakeview.UpdateSchedule(ctx, updateScheduleReq)
if err != nil { if err != nil {

View File

@ -55,6 +55,7 @@ func newCreate() *cobra.Command {
cmd := &cobra.Command{} cmd := &cobra.Command{}
var createReq catalog.CreateOnlineTableRequest var createReq catalog.CreateOnlineTableRequest
createReq.Table = &catalog.OnlineTable{}
var createJson flags.JsonFlag var createJson flags.JsonFlag
var createSkipWait bool var createSkipWait bool
@ -86,7 +87,7 @@ func newCreate() *cobra.Command {
w := root.WorkspaceClient(ctx) w := root.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") { if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq) diags := createJson.Unmarshal(&createReq.Table)
if diags.HasError() { if diags.HasError() {
return diags.Error() return diags.Error()
} }