Skip to content

Commit 643eefc

Browse files
committed
Add command to output info about an order's browser
1 parent e94e11b commit 643eefc

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

cmd/orders/orders.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package orders
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"strings"
7+
8+
"github.com/urfave/cli/v2"
9+
"github.com/ScreenStaring/shopify-dev-tools/cmd"
10+
"github.com/cheynewallace/tabby"
11+
)
12+
13+
var Cmd cli.Command
14+
15+
func userAgentAction(c *cli.Context) error {
16+
if(c.Args().Len() == 0) {
17+
return fmt.Errorf("You must supply an order id")
18+
}
19+
20+
id, err := strconv.ParseInt(c.Args().Get(0), 10, 64)
21+
if err != nil {
22+
return fmt.Errorf("Order id '%s' is invalid: must be an int", c.Args().Get(0))
23+
}
24+
25+
order, err := cmd.NewShopifyClient(c).Order.Get(id, nil)
26+
if err != nil {
27+
return fmt.Errorf("Cannot find order: %s", err)
28+
}
29+
30+
31+
t := tabby.New()
32+
t.AddLine("Id", order.ID)
33+
t.AddLine("User Agent", order.ClientDetails.UserAgent)
34+
t.AddLine("Display", fmt.Sprintf("%dx%d", order.ClientDetails.BrowserWidth, order.ClientDetails.BrowserHeight))
35+
t.AddLine("Accept Language", order.ClientDetails.AcceptLanguage)
36+
t.AddLine("IP", order.BrowserIp)
37+
t.AddLine("Session", order.ClientDetails.SessionHash)
38+
t.Print()
39+
40+
// TODO: Make a function for this. We use it several places.
41+
fmt.Printf("%s\n", strings.Repeat("-", 20))
42+
43+
return nil
44+
}
45+
46+
func init() {
47+
Cmd = cli.Command{
48+
Name: "orders",
49+
Aliases: []string{"o"},
50+
Usage: "Information about orders",
51+
Subcommands: []*cli.Command{
52+
{
53+
Name: "useragent",
54+
Aliases: []string{"ua"},
55+
Usage: "Info about the web browser used to place the order",
56+
Flags: cmd.Flags,
57+
Action: userAgentAction,
58+
},
59+
},
60+
}
61+
}

sdt.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/urfave/cli/v2"
88
"github.com/ScreenStaring/shopify-dev-tools/cmd/admin"
99
"github.com/ScreenStaring/shopify-dev-tools/cmd/metafields"
10+
"github.com/ScreenStaring/shopify-dev-tools/cmd/orders"
1011
"github.com/ScreenStaring/shopify-dev-tools/cmd/scripttags"
1112
"github.com/ScreenStaring/shopify-dev-tools/cmd/shop"
1213
"github.com/ScreenStaring/shopify-dev-tools/cmd/webhooks"
@@ -23,6 +24,7 @@ func main() {
2324
Commands: []*cli.Command{
2425
&admin.Cmd,
2526
&metafields.Cmd,
27+
&orders.Cmd,
2628
&shop.Cmd,
2729
&scripttags.Cmd,
2830
&webhooks.Cmd,

0 commit comments

Comments
 (0)