Skip to content

Commit c9025df

Browse files
committed
Support for timeout and verbose options + add go.mod
1 parent dbc93e0 commit c9025df

6 files changed

Lines changed: 47 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ Options
4949
-p --password password Shopify API password; defaults to the SHOPIFY_API_PASSWORD environment variable
5050
-r --json-root property use property as the top-level property for each JSON object
5151
-t --token token Shopify API token; defaults to the SHOPIFY_API_TOKEN environment variable
52+
--timeout integer set Shopify client timeout (default: 10 seconds)
5253
-v --version display version information
54+
--verbose output Shopify API request/response (default: false)
5355
5456
By default data is output to a CSV file.
5557

exportformat/csv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
"strconv"
88

9-
shopify "github.com/bold-commerce/go-shopify"
9+
shopify "github.com/bold-commerce/go-shopify/v3"
1010
)
1111

1212
type CSV struct {

exportformat/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
"strconv"
88

9-
shopify "github.com/bold-commerce/go-shopify"
9+
shopify "github.com/bold-commerce/go-shopify/v3"
1010
)
1111

1212
type JSON struct {

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/screenstaring/shopify_id_export
2+
3+
go 1.16
4+
5+
require github.com/bold-commerce/go-shopify/v3 v3.17.0 // indirect

go.sum

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
github.com/bold-commerce/go-shopify/v3 v3.17.0 h1:1qZenleSsJMVFh5hu6R2z2NfmWP5xG0P8MawePr46K0=
2+
github.com/bold-commerce/go-shopify/v3 v3.17.0/go.mod h1:qOrEfYoy5RRO/PAq4vGyHW03NZmt2iX/fPGuaZwemtI=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
5+
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
6+
github.com/jarcoal/httpmock v1.3.0/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
7+
github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM=
8+
github.com/shopspring/decimal v0.0.0-20200105231215-408a2507e114 h1:Pm6R878vxWWWR+Sa3ppsLce/Zq+JNTs6aVvRu13jv9A=
9+
github.com/shopspring/decimal v0.0.0-20200105231215-408a2507e114/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=

main.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ package main
33
import (
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"
1416
const shopifyFields = "id,title,product_type,handle,variants"
1517

1618
const 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
2731
By default data is output to a CSV file.
2832
@@ -75,8 +79,11 @@ func dumpProducts(client *shopify.Client, dumper dumper) error {
7579

7680
func 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

Comments
 (0)