|
| 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 | +} |
0 commit comments