From a711bca42d64c1d0f391d4c834a1406a28e7fc5a Mon Sep 17 00:00:00 2001 From: buzzy Date: Thu, 15 Sep 2022 21:23:04 +0800 Subject: [PATCH 1/5] Change to manual version control --- .github/workflows/build.yml | 30 ------------------------------ .github/workflows/release.yml | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 30 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 6f1fcb0..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Build CLI - -on: - workflow_dispatch: - -jobs: - compile: - name: Compile - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: actions/setup-go@v3 - with: - go-version: '>=1.18.0' - - - name: Compile - run: | - VERSION="0.$(git rev-list --count HEAD).0" - echo "version=$VERSION" >> $GITHUB_ENV - sed -i "s/0.0.0/${VERSION}/" main.go - bash build-all.sh $VERSION - - - name: Release - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh release create v${{ env.version }} --generate-notes ./bin/*.zip ./bin/*_SHA256SUMS diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a4c4eb8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Compile and Release + +on: + workflow_dispatch: + inputs: + version: + type: string + description: Version for new release + required: true + default: 0.0.0 + +jobs: + compile: + name: Compile and Release + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: '>=1.18.0' + + - name: Compile and Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + VERSION="${{ github.event.inputs.version }}" + sed -i "s/0.0.0/${VERSION}/" main.go + bash build-all.sh $VERSION + gh release create v$VERSION --generate-notes ./bin/*.zip ./bin/*_SHA256SUMS From dc0e37ccdef2a21c9db483d643125c6e5ca1316f Mon Sep 17 00:00:00 2001 From: buzzy Date: Fri, 16 Sep 2022 21:38:55 +0800 Subject: [PATCH 2/5] Add color to flag-values to make it easier to read --- help.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/help.go b/help.go index 1c248e2..48ae61b 100644 --- a/help.go +++ b/help.go @@ -285,6 +285,7 @@ func printHelpCommand(command string) { varType = "LIST" } + completeColor := "-" + flg + colorBlue + "=" + varType + colorReset complete := "-" + flg + "=" + varType //TODO: IF DESCRIPTION INCLUDES LINK, CONVERT IT TO A HTTP LINK TO THE DOCS @@ -294,7 +295,7 @@ func printHelpCommand(command string) { description = description + colorRed + " [*required]" + colorReset } - fmt.Println(" ", complete, strings.Repeat(" ", maxLength-len(complete)+1), description) + fmt.Println(" ", completeColor, strings.Repeat(" ", maxLength-len(complete)+1), description) if flags[flg].enum != nil { From fc2eeeeb93d7ddbcebd300efc8280684c6e70f98 Mon Sep 17 00:00:00 2001 From: buzzy Date: Sat, 17 Sep 2022 00:38:29 +0800 Subject: [PATCH 3/5] Rename flags that contains non-standard chars --- command.go | 18 ++++++++++++++---- help.go | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/command.go b/command.go index 5b78114..58cbefb 100644 --- a/command.go +++ b/command.go @@ -9,6 +9,7 @@ import ( "net/http" "net/url" "os" + "regexp" "strconv" "strings" @@ -18,6 +19,7 @@ import ( type Parameter struct { varType string + orgName string description string required bool enum []any @@ -25,6 +27,13 @@ type Parameter struct { value *string } +//Rename flags with odd names that causes issues in some shells +func renameFlag(name string) string { + m := regexp.MustCompile(`\[(.*)\]`) + + return m.ReplaceAllString(name, "-$1") +} + func parseCommand(format string, verbose bool) { doc := loadAPI() @@ -63,14 +72,15 @@ func parseCommand(format string, verbose bool) { parameter.Value.Schema.Value.Type == "integer" || parameter.Value.Schema.Value.Type == "array" { - flags[parameter.Value.Name] = Parameter{ + flags[renameFlag(parameter.Value.Name)] = Parameter{ location: parameter.Value.In, varType: "string", + orgName: parameter.Value.Name, required: parameter.Value.Required, value: new(string), } - subFlag.StringVar(flags[parameter.Value.Name].value, parameter.Value.Name, "", parameter.Value.Description) + subFlag.StringVar(flags[renameFlag(parameter.Value.Name)].value, renameFlag(parameter.Value.Name), "", parameter.Value.Description) continue } @@ -191,11 +201,11 @@ func parseCommand(format string, verbose bool) { switch parameter.location { case "query": //This flag value should be sent as a query parameter - query.Add(name, *parameter.value) + query.Add(parameter.orgName, *parameter.value) case "path": //This flag value goes in the URI - uri = strings.Replace(uri, "{"+name+"}", *parameter.value, 1) + uri = strings.Replace(uri, "{"+parameter.orgName+"}", *parameter.value, 1) } } diff --git a/help.go b/help.go index 48ae61b..c651216 100644 --- a/help.go +++ b/help.go @@ -133,9 +133,9 @@ func printHelpCommand(command string) { enum = parameter.Value.Schema.Value.Items.Value.Enum } - flags[parameter.Value.Name] = Parameter{ + flags[renameFlag(parameter.Value.Name)] = Parameter{ varType: parameter.Value.Schema.Value.Type, - description: parameter.Value.Description, + description: renameFlag(parameter.Value.Description), required: parameter.Value.Required, enum: enum, } From ff3f870d3968138d9608d367b96cad029013647d Mon Sep 17 00:00:00 2001 From: buzzy Date: Mon, 19 Sep 2022 17:04:15 +0800 Subject: [PATCH 4/5] Treat all non-2xx responses as errors --- command.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/command.go b/command.go index 58cbefb..e27d26c 100644 --- a/command.go +++ b/command.go @@ -429,11 +429,7 @@ func callAPI(method string, uri string, query url.Values, body string, contentTy fmt.Println(string(resBody)) } - switch res.StatusCode { - case 400: - showError(resBody) - - case 404: + if res.StatusCode >= 300 { showError(resBody) } From 763ba507ddf6c8c1fcc2137cba95b952bb4acc49 Mon Sep 17 00:00:00 2001 From: buzzy Date: Mon, 19 Sep 2022 17:34:03 +0800 Subject: [PATCH 5/5] Send empty json-array on empty responses --- command.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/command.go b/command.go index e27d26c..0e74848 100644 --- a/command.go +++ b/command.go @@ -450,6 +450,11 @@ func callAPI(method string, uri string, query url.Values, body string, contentTy break } + //If data is empty, just send empty array + if len(response.Search("data").Children()) == 0 && len(response.Search("data").ChildrenMap()) == 0 { + break + } + arrayResponse := response.Exists("data", "0") newItems := parseData(response)