Skip to content

Commit 3df19c1

Browse files
authored
Implement nelson stacks list -u (#30)
* Implement `nelson stacks list -u` The arg for this was implemented but wasn't actually plumbed through to the API call. This PR plumbs it through, and also tidies a few minor things up. I've tested it against a Nelson cluster. * build query string using url.Values instead
1 parent c1243f7 commit 3df19c1

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/github.com/getnelson/nelson/main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ import (
2020
"crypto/sha256"
2121
"encoding/base64"
2222
"fmt"
23-
"github.com/parnurzeal/gorequest"
24-
"gopkg.in/urfave/cli.v1"
2523
"io/ioutil"
2624
"log"
2725
"os"
2826
"regexp"
2927
"strconv"
3028
"strings"
3129
"time"
30+
31+
"github.com/parnurzeal/gorequest"
32+
"gopkg.in/urfave/cli.v1"
3233
)
3334

3435
var globalTimeoutSeconds int
@@ -56,6 +57,7 @@ func main() {
5657
var selectedNamespace string
5758
var selectedLoadbalancer string
5859
var selectedStatus string
60+
var selectedUnit string
5961
var selectedUnitPrefix string
6062
var selectedVersion string
6163
var selectedPort int64
@@ -645,8 +647,8 @@ func main() {
645647
cli.StringFlag{
646648
Name: "unit, u",
647649
Value: "",
648-
Usage: "Only list stacks that match a specified unit prefix",
649-
Destination: &selectedUnitPrefix,
650+
Usage: "Only list stacks that match the specified unit",
651+
Destination: &selectedUnit,
650652
},
651653
cli.StringFlag{
652654
Name: "datacenters, d",
@@ -688,7 +690,7 @@ func main() {
688690

689691
pi.Start()
690692
cfg := LoadDefaultConfigOrExit(http)
691-
r, e := ListStacks(selectedDatacenter, selectedNamespace, selectedStatus, http, cfg)
693+
r, e := ListStacks(selectedDatacenter, selectedNamespace, selectedStatus, selectedUnit, http, cfg)
692694
pi.Stop()
693695
if e != nil {
694696
PrintTerminalErrors(e)

src/github.com/getnelson/nelson/stack.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import (
2020
"encoding/json"
2121
"errors"
2222
"fmt"
23+
"net/url"
24+
"strconv"
25+
2326
"github.com/fatih/color"
2427
"github.com/parnurzeal/gorequest"
25-
"strconv"
2628
)
2729

2830
/////////////////// MANUAL DEPLOYMENT ///////////////////
@@ -300,23 +302,28 @@ type Stack struct {
300302
Weight int64 `json:"weight,omitempty"`
301303
}
302304

303-
func ListStacks(delimitedDcs string, delimitedNamespaces string, delimitedStatuses string, http *gorequest.SuperAgent, cfg *Config) (list []Stack, err []error) {
305+
func ListStacks(delimitedDcs string, delimitedNamespaces string, delimitedStatuses string, unit string, http *gorequest.SuperAgent, cfg *Config) (list []Stack, err []error) {
304306
uri := "/v1/deployments?"
307+
qs := url.Values{}
305308
// set the datacenters if specified
306309
if isValidCommaDelimitedList(delimitedDcs) {
307-
uri = uri + "dc=" + delimitedDcs + "&"
310+
qs.Set("dc", delimitedDcs)
308311
}
309312
if isValidCommaDelimitedList(delimitedStatuses) {
310-
uri = uri + "status=" + delimitedStatuses + "&"
313+
qs.Set("status", delimitedStatuses)
311314
} else {
312315
// if the user didnt specify statuses, they probally want all the stacks except historical terminated ones.
313-
uri = uri + "status=pending,deploying,warming,ready,deprecated,failed&"
316+
qs.Set("status", "pending,deploying,warming,ready,deprecated,failed")
314317
}
315318
if isValidCommaDelimitedList(delimitedNamespaces) {
316-
uri = uri + "ns=" + delimitedNamespaces
319+
qs.Set("ns", delimitedNamespaces)
317320
} else {
318-
uri = uri + "ns=dev,qa,prod"
321+
qs.Set("ns", "dev,qa,prod")
322+
}
323+
if unit != "" {
324+
qs.Set("unit", unit)
319325
}
326+
uri = uri + qs.Encode()
320327

321328
r, bytes, errs := AugmentRequest(
322329
http.Get(cfg.Endpoint+uri), cfg).EndBytes()

0 commit comments

Comments
 (0)