Skip to content

Commit

Permalink
fix: abbreviated cli flags
Browse files Browse the repository at this point in the history
BREAKING CHANGE: --version no longer returns a version number. First of all, semantic-release goes with removing the version number from your package.json. But also, the version number really shouldn't matter.

Furthermore, you can now use all flags in an abbreviated manner as long as they are unambiguous. For example:
`android-icons --si xxhdpi` works just like `android-icons --size xxhdpi` does. This works for all flags.
  • Loading branch information
davidnpma committed Apr 5, 2015
1 parent f1aa6ec commit fc7b224
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
56 changes: 31 additions & 25 deletions bin/android-icons.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
#!/usr/bin/env node
'use strict'
var abbrev = require('abbrev')
var argv = require('minimist')(process.argv.slice(2), abbrev('help', 'version', 'size', 'format'))
var pkg = require('../package.json')
var argv = require('yargs')
var icons = require('../')

function help () {
console.log([
pkg.description,
'',
'Use `--format json` to set output to JSON.',
'Get specifc icon by size or name by using `--size`.',
'',
'Examples:',
' $ android-icons --size 48',
' mdpi.png,48',
'',
' $ android-icons --size 48 --format json',
' {"name":"mdpi.png","width":48}',
'',
' $ android-icons --size xhdpi',
' xhdpi.png,96'
].join('\n'))
}
// help
argv.help('help')
argv.alias('h', 'help')

// register abbreviated aliases
var abbrevs = abbrev(['help', 'size', 'format'])
var aliases = Object.keys(abbrevs)
aliases.forEach(function (alias) {
if (alias !== abbrevs[alias]) {
argv.alias(alias, abbrevs[alias])
}
})

// document options
argv.option('size', {
description: 'number of pixels (width) or string identifiying the icon image'
})
argv.option('format', {
description: 'format of the output to stdout (csv or json)'
})

// will show up in help
argv.usage('Usage: android-icons [options]')

argv.example('$ android-icons --size 48', 'mdpi.png,48')
argv.example('$ android-icons --size 48 --format json', '{"name":"mdpi.png","width":48}')
argv.example('$ android-icons --size xhdpi', 'xhdpi.png,96')

argv = argv.argv

function formatLog (icons, argv) {
var format = (argv.format || 'csv').toLowerCase()
Expand All @@ -38,12 +48,8 @@ function formatLog (icons, argv) {
}

function cli () {
if (argv.help) return help()

if (argv.version) return console.log(pkg.version)

var options = {
size: argv.size || argv.s
size: argv.size
}

var output = icons(options)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bin": "./bin/android-icons.js",
"dependencies": {
"abbrev": "^1.0.5",
"minimist": "^1.1.0"
"yargs": "^3.7.0"
},
"devDependencies": {
"semantic-release": "^3.0.4",
Expand Down

0 comments on commit fc7b224

Please sign in to comment.