clubhouse-cli
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "clubhouse-cli", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A command line tool for viewing, creating and updating clubhouse.io stories", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -67,2 +67,3 @@ # clubhouse-cli | ||
-f, --format [template] Format each story output by template | ||
-r, --sort [field] Sort stories by field (accessor[:asc|desc][,next]) | ||
-h, --help output usage information | ||
@@ -112,2 +113,6 @@ ~~~ | ||
#### Story Output Sorting | ||
The default sorting for stories found is `state.position:asc,id:asc`, which translates to "sort by associated state position ascending, then by story id ascending within the same state." | ||
### Story | ||
@@ -114,0 +119,0 @@ |
@@ -27,3 +27,4 @@ const chalk = require('chalk'); | ||
return a.concat(b); | ||
}, []); | ||
}, []) | ||
.sort(sortStories(program)); | ||
}; | ||
@@ -96,2 +97,34 @@ const fetchStories = async (project) => { | ||
};}; | ||
const sortStories = (program) => { | ||
const fields = program.sort | ||
.split(',') | ||
.map(s => { | ||
return s.split(':') | ||
.map(ss => ss.split('.')); | ||
}); | ||
const pluck = (acc, val) => { | ||
if (acc[val] === undefined) | ||
return {}; | ||
return acc[val]; | ||
}; | ||
return (a, b) => { | ||
return fields.reduce((acc, field) => { | ||
if (acc !== 0) | ||
return acc; | ||
const ap = field[0].reduce(pluck, a); | ||
const bp = field[0].reduce(pluck, b); | ||
if (ap === bp) | ||
return 0; | ||
const direction = (field[1] || [''])[0].match(/des/i) ? 1 : -1; | ||
if (ap > bp) { | ||
if (direction > 0) | ||
return -1; | ||
} else { | ||
if (direction < 0) | ||
return -1; | ||
} | ||
return 1; | ||
}, 0); | ||
}; | ||
}; | ||
@@ -98,0 +131,0 @@ const printStory = (program) => { return (story) => { |
Sorry, the diff of this file is not supported yet
51181
273
288