@@ -3,14 +3,16 @@ package main
33import (
44 "flag"
55 "fmt"
6+ "net/http"
67 "os"
78 "strings"
9+ "time"
810
9- shopify "github.com/bold-commerce/go-shopify"
11+ shopify "github.com/bold-commerce/go-shopify/v3 "
1012 "github.com/screenstaring/shopify_id_export/exportformat"
1113)
1214
13- const version = "v0.0.4 "
15+ const version = "v0.0.5 "
1416const shopifyFields = "id,title,product_type,handle,variants"
1517
1618const usage = `shopify_id_export [hjv] [-k key] [-p password] [-r root-property] [-t token] shop
@@ -21,8 +23,10 @@ Options
2123-k --key key Shopify API key; defaults to the SHOPIFY_API_KEY environment variable
2224-p --password password Shopify API password; defaults to the SHOPIFY_API_PASSWORD environment variable
2325-r --json-root property use property as the top-level property for each JSON object
26+ --timeout integer set Shopify client timeout (default: 10 seconds)
2427-t --token token Shopify API token; defaults to the SHOPIFY_API_TOKEN environment variable
2528-v --version display version information
29+ --verbose output Shopify API request/response (default: false)
2630
2731By default data is output to a CSV file.
2832
@@ -75,8 +79,11 @@ func dumpProducts(client *shopify.Client, dumper dumper) error {
7579
7680func main () {
7781 var key , password , token string
78- var asJSON , showHelp , showVersion bool
82+ var asJSON , showHelp , showVersion , verbose bool
7983 var jsonRoot string
84+ var timeout int64
85+ var options []shopify.Option
86+ var client * shopify.Client
8087
8188 flag .Usage = func () {
8289 exitFailure (fmt .Sprintf (usage , strings .Join (exportformat .JSONRootProperties , ", " )), 2 )
@@ -94,8 +101,10 @@ func main() {
94101 flag .StringVar (& jsonRoot , "json-root" , "" , "" )
95102 flag .StringVar (& token , "t" , os .Getenv ("SHOPIFY_API_TOKEN" ), "" )
96103 flag .StringVar (& token , "token" , os .Getenv ("SHOPIFY_API_TOKEN" ), "" )
104+ flag .Int64Var (& timeout , "timeout" , - 1 , "" )
97105 flag .BoolVar (& showVersion , "v" , false , "" )
98106 flag .BoolVar (& showVersion , "version" , false , "" )
107+ flag .BoolVar (& verbose , "verbose" , false , "" )
99108
100109 flag .Parse ()
101110 argv := flag .Args ()
@@ -123,7 +132,23 @@ func main() {
123132 }
124133
125134 app := shopify.App {ApiKey : key , Password : password }
126- client := shopify .NewClient (app , argv [0 ], token )
135+
136+ if timeout > - 1 {
137+ options = append (
138+ options ,
139+ shopify .WithHTTPClient (
140+ & http.Client {
141+ Timeout : time .Second * time .Duration (timeout ),
142+ },
143+ ),
144+ )
145+ }
146+
147+ if verbose {
148+ options = append (options , shopify .WithLogger (& shopify.LeveledLogger {Level : shopify .LevelDebug }))
149+ }
150+
151+ client = shopify .NewClient (app , argv [0 ], token , options ... )
127152
128153 err = dumpProducts (client , dumper )
129154 dumpErr := dumper .Close ()
0 commit comments