Skip to content

Commit

Permalink
feat: add command-line interface
Browse files Browse the repository at this point in the history
closes #1
  • Loading branch information
gyoshev committed Feb 4, 2017
1 parent 459f706 commit 1a667c5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
demo/
test/
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,34 @@ Returns an array of suggestions, sorted by difference from the target color.
Example of suggesting LESS functions:

> cuttle.suggest("#000", "#333");

[ { difference: 0, format: "lighten(@input, 20%)" } ]

Example of suggesting SASS functions:

> cuttle.suggest("#ae465f", "#aeae46", "sass");


[ { difference: 0.4477, format: "adjust-hue($input, 75)" } ]


## CLI Usage

Install as a global module through `npm install -g cuttle`. Then get suggestions by running

$ cuttle --from #ae465f --to #aeae46 --dialect sass

[ { difference: 0.4477, format: "adjust-hue($input, 75)" } ]

Full usage options:

Usage: cuttle [options]

Suggests transition functions between colors

Options:

-h, --help output usage information
-V, --version output the version number
-f, --from <color> input color (e.g. #ae465f)
-t, --to <color> output color (e.g. #aeae46)
-d, --dialect <dialect> dialect of output, either "sass" or "less"
34 changes: 34 additions & 0 deletions bin/cuttle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env node

var program = require('commander');
var package = require('../package.json');
var suggest = require('../lib/main').suggest;

var color = /^(#?[0-9a-f]{3,6})$/i;

program
.version(package.version)
.description('Suggests transition functions between colors')
.option('-f, --from <color>', 'input color (e.g. #ae465f)', color)
.option('-t, --to <color>', 'output color (e.g. #aeae46)', color)
.option('-d, --dialect <dialect>', 'dialect of output (either "sass" or "less")', /^(sass|less)$/i, 'less')
.parse(process.argv);

if (!color.test(program.from) || !color.test(program.to)) {
console.error('Both --from and --to colors must be specified to suggest a transition!');

program.outputHelp();

process.exit(1);
}

var convertSuggestion = function(s) {
return {
difference: s.difference,
format: s.format
};
}

var suggestions = suggest(program.from, program.to, program.dialect).map(convertSuggestion);

console.log(suggestions);
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "0.0.0",
"description": "Determine color function based on color examples",
"main": "lib/main.js",
"bin": {
"cuttle": "bin/cuttle.js"
},
"scripts": {
"test": "grunt test"
},
Expand Down Expand Up @@ -30,7 +33,8 @@
"mocha": "~2.2.5"
},
"dependencies": {
"less": "~2.5.1",
"chroma-js": "~1.0.1"
"chroma-js": "~1.0.1",
"commander": "^2.9.0",
"less": "~2.5.1"
}
}

0 comments on commit 1a667c5

Please sign in to comment.