package terminal import ( "encoding/json" "errors" "fmt" "git.myservermanager.com/varakh/upda/api" "git.myservermanager.com/varakh/upda/server" "git.myservermanager.com/varakh/upda/util" "github.com/go-resty/resty/v2" "github.com/urfave/cli/v2" "log" "os" "text/tabwriter" ) const ( name = "upda-cli" desc = "a commandline helper for upda" version = server.Version envServerUrl = "UPDA_SERVER_URL" envAdminUser = "UPDA_ADMIN_USER" envAdminPassword = "UPDA_ADMIN_PASSWORD" envWebhookId = "UPDA_WEBHOOK_ID" envWebhookToken = "UPDA_WEBHOOK_TOKEN" flagServerUrl = "server-url" flagAdminUser = "admin-user" flagAdminPass = "admin-pass" flagWebhookId = "webhook-id" flagWebhookToken = "webhook-token" flagUpdatePageSize = "page-size" flagRaw = "raw" webhooksUrlPath = "/api/v1/webhooks" updatesUrlPath = "/api/v1/updates" ) func Start() { var raw bool var serverUrl string var adminUser string var adminPassword string var webhookId string var webhookToken string var updatePageSize int64 rawFlag := &cli.BoolFlag{ Name: flagRaw, Usage: "on success raw JSON data from response is returned", Aliases: []string{"r"}, Value: false, Destination: &raw, } serverUrlFlag := &cli.StringFlag{ Name: flagServerUrl, Usage: "the server url (FQDN without context path)", Required: true, Aliases: []string{"s"}, EnvVars: []string{envServerUrl}, Destination: &serverUrl, } adminUserFlag := &cli.StringFlag{ Name: flagAdminUser, Usage: "admin user", Required: true, Aliases: []string{"u"}, EnvVars: []string{envAdminUser}, Destination: &adminUser, } adminPasswordFlag := &cli.StringFlag{ Name: flagAdminPass, Usage: "admin password", Required: true, Aliases: []string{"p"}, EnvVars: []string{envAdminPassword}, Destination: &adminPassword, } webhookIdFlag := &cli.StringFlag{ Name: flagWebhookId, Usage: "webhook id", Required: true, Aliases: []string{"i"}, EnvVars: []string{envWebhookId}, Destination: &webhookId, } webhookTokenFlag := &cli.StringFlag{ Name: flagWebhookToken, Usage: "webhook token", Required: true, Aliases: []string{"t"}, EnvVars: []string{envWebhookToken}, Destination: &webhookToken, } updatePageSizeFlag := &cli.Int64Flag{ Name: flagUpdatePageSize, Usage: "update show page size", Value: 10000, Required: false, Aliases: []string{"ps"}, Destination: &updatePageSize, } cli.VersionFlag = &cli.BoolFlag{ Name: "version", Aliases: []string{"v"}, Usage: "show version", } app := &cli.App{ Name: name, Usage: desc, Version: version, EnableBashCompletion: true, Commands: []*cli.Command{ { Name: "webhook", Aliases: []string{"w"}, Usage: "Options for webhook", Subcommands: []*cli.Command{ { Name: "create", Usage: "Creates a webhook", Aliases: []string{"c"}, Flags: []cli.Flag{ serverUrlFlag, adminUserFlag, adminPasswordFlag, rawFlag, }, ArgsUsage: "