package terminal import ( "encoding/json" "errors" "fmt" "git.myservermanager.com/varakh/upda/api" "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 = "3.0.0" envServerUrl = "UPDA_SERVER_URL" envUser = "UPDA_USER" envPassword = "UPDA_PASSWORD" envWebhookId = "UPDA_WEBHOOK_ID" envWebhookToken = "UPDA_WEBHOOK_TOKEN" flagServerUrl = "server-url" flagUser = "user" flagPass = "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 user string var password 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, } userFlag := &cli.StringFlag{ Name: flagUser, Usage: "user", Required: true, Aliases: []string{"u"}, EnvVars: []string{envUser}, Destination: &user, } passwordFlag := &cli.StringFlag{ Name: flagPass, Usage: "password", Required: true, Aliases: []string{"p"}, EnvVars: []string{envPassword}, Destination: &password, } 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, userFlag, passwordFlag, rawFlag, }, ArgsUsage: "