Skip to content

Commit

Permalink
Added option to return all worksheets
Browse files Browse the repository at this point in the history
  • Loading branch information
bassarisse committed May 3, 2017
1 parent cf5d69e commit 70662f0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Next
## New
- Service Account auth support
- Option to return all worksheets

## Changes
- Removed user/password auth method (BREAKING)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Options:
-t, --token <token> Auth token acquired externally
-y, --tokentype <tokentype> Type of the informed token (defaults to Bearer)
-w, --worksheet <n> Worksheet index or title (defaults to first worksheet, can be repeated)
-a, --all-worksheets Return all worksheets (worksheet option is ignored)
-c, --hash <column> Column to hash the final object
-m, --property-mode <mode> How to handle property names: "camel" (default), "pascal", "nospace" or "none"
-i, --vertical Use the first column as header
Expand Down
1 change: 1 addition & 0 deletions gsjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ program
.option('-t, --token <token>', 'Auth token acquired externally')
.option('-y, --tokentype <tokentype>', 'Type of the informed token (defaults to Bearer)')
.option('-w, --worksheet <n>', 'Worksheet index or title (defaults to first worksheet, can be repeated)', handleWorksheetIdentifiers)
.option('-a, --all-worksheets', 'Return all worksheets (worksheet option is ignored)')
.option('-c, --hash <column>', 'Column to hash the final object')
.option('-m, --property-mode <mode>', 'How to handle property names: "camel" (default), "pascal", "nospace" or "none"', /^(camel|pascal|nospace|none)$/i, 'camel')
.option('-i, --vertical', 'Use the first column as header')
Expand Down
7 changes: 5 additions & 2 deletions helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,15 @@ exports.getWorksheets = function(options) {

exports.spreadsheetToJson = function(options) {

// if an array is not passed here, expects only first result
var expectMultipleWorksheets = Array.isArray(options.worksheet)
var allWorksheets = !!options.allWorksheets
var expectMultipleWorksheets = allWorksheets || Array.isArray(options.worksheet)

return exports.getWorksheets(options)
.then(function(worksheets) {

if (allWorksheets)
return worksheets

var identifiers = normalizeWorksheetIdentifiers(options.worksheet)

var selectedWorksheets = worksheets.filter(function(worksheet, index) {
Expand Down

0 comments on commit 70662f0

Please sign in to comment.