Skip to content

Commit d73bd4d

Browse files
committed
Add command to print access scopes granted to the given shop/token
1 parent 643eefc commit d73bd4d

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ Information about the given shop
143143
sdt shop command [command options] [arguments...]
144144

145145
COMMANDS:
146-
info, i Information about the shop
147-
help, h Shows a list of commands or help for one command
146+
access, a List access scopes granted to the shop's token
147+
info, i Information about the shop
148+
help, h Shows a list of commands or help for one command
148149

149150
OPTIONS:
150151
--help, -h show help (default: false)

cmd/shop/shop.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"reflect"
66
"regexp"
7+
"sort"
78
"strings"
89

910
"github.com/urfave/cli/v2"
@@ -25,6 +26,30 @@ func formatField(field string) string {
2526

2627
func accessAction(c *cli.Context) error {
2728
// not supported, need to update API client
29+
30+
scopes, err := cmd.NewShopifyClient(c).AccessScopes.List(nil)
31+
if err != nil {
32+
return fmt.Errorf("Cannot get info for shop: %s", err)
33+
}
34+
35+
if len(scopes) == 0 {
36+
fmt.Println("No scopes defined")
37+
return nil
38+
}
39+
40+
t := tabby.New()
41+
t.AddHeader("Scope")
42+
43+
sort.Slice(scopes, func(i, j int) bool {
44+
return strings.Compare(scopes[i].Handle, scopes[j].Handle) == -1
45+
})
46+
47+
for _, scope := range scopes {
48+
t.AddLine(scope.Handle)
49+
}
50+
51+
t.Print()
52+
2853
return nil
2954
}
3055

@@ -52,13 +77,13 @@ func init() {
5277
Aliases: []string{"s"},
5378
Usage: "Information about the given shop",
5479
Subcommands: []*cli.Command{
55-
// {
56-
// Name: "access",
57-
// Aliases: []string{"a"},
58-
// Usage: "Permissions granted to the given token/key",
59-
// Flags: cmd.Flags,
60-
// Action: accessAction,
61-
// },
80+
{
81+
Name: "access",
82+
Aliases: []string{"a"},
83+
Usage: "List access scopes granted to the shop's token",
84+
Flags: cmd.Flags,
85+
Action: accessAction,
86+
},
6287
{
6388
Name: "info",
6489
Aliases: []string{"i"},

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ go 1.15
44

55
require (
66
github.com/bold-commerce/go-shopify v2.3.0+incompatible // indirect
7-
github.com/bold-commerce/go-shopify/v3 v3.11.0
7+
github.com/bold-commerce/go-shopify/v3 v3.12.0
88
github.com/cheynewallace/tabby v1.1.1
99
github.com/clbanning/mxj v1.8.4
1010
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
1111
github.com/google/go-querystring v1.1.0 // indirect
1212
github.com/pkg/browser v0.0.0-20201207095918-0426ae3fba23
1313
github.com/russross/blackfriday/v2 v2.1.0 // indirect
14-
github.com/shopspring/decimal v1.2.0 // indirect
14+
github.com/shopspring/decimal v1.3.1 // indirect
1515
github.com/urfave/cli/v2 v2.3.0
1616
)

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/bold-commerce/go-shopify v2.3.0+incompatible h1:AiedLiOoFWp7iVO8n6JJO
44
github.com/bold-commerce/go-shopify v2.3.0+incompatible/go.mod h1:R9OKSw+EViwy7MGrAxma3q+Vqq8kMyZu+OJhx/dcw6s=
55
github.com/bold-commerce/go-shopify/v3 v3.11.0 h1:3FXbtpUmhz91kswPxrIQWFneoxOTW+RWbmhp05bISjI=
66
github.com/bold-commerce/go-shopify/v3 v3.11.0/go.mod h1:MxKdd8wvTKrRLh19VLZsJwQy0Qw/8GO9TRol+6ErDxg=
7+
github.com/bold-commerce/go-shopify/v3 v3.12.0 h1:zB65ikoXWKOfcQPZGX+1yg4gUDuMrndiqMW53rdrBrs=
8+
github.com/bold-commerce/go-shopify/v3 v3.12.0/go.mod h1:MxKdd8wvTKrRLh19VLZsJwQy0Qw/8GO9TRol+6ErDxg=
79
github.com/cheynewallace/tabby v1.1.1 h1:JvUR8waht4Y0S3JF17G6Vhyt+FRhnqVCkk8l4YrOU54=
810
github.com/cheynewallace/tabby v1.1.1/go.mod h1:Pba/6cUL8uYqvOc9RkyvFbHGrQ9wShyrn6/S/1OYVys=
911
github.com/clbanning/mxj v1.8.4 h1:HuhwZtbyvyOw+3Z1AowPkU87JkJUSv751ELWaiTpj8I=
@@ -15,6 +17,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
1517
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
1618
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
1719
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
20+
github.com/jarcoal/httpmock v1.0.4 h1:jp+dy/+nonJE4g4xbVtl9QdrUNbn6/3hDT5R4nDIZnA=
1821
github.com/jarcoal/httpmock v1.0.4/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
1922
github.com/pkg/browser v0.0.0-20201207095918-0426ae3fba23 h1:dofHuld+js7eKSemxqTVIo8yRlpRw+H1SdpzZxWruBc=
2023
github.com/pkg/browser v0.0.0-20201207095918-0426ae3fba23/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ=
@@ -25,6 +28,8 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
2528
github.com/shopspring/decimal v0.0.0-20200105231215-408a2507e114/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
2629
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
2730
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
31+
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
32+
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
2833
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
2934
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
3035
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=

0 commit comments

Comments
 (0)