electron 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.npmignore CHANGED
@@ -1,4 +1,5 @@
1
1
  .git*
2
+ docs/
2
3
  support/
3
4
  test/
4
5
  .DS_Store
package/History.md CHANGED
@@ -1,4 +1,17 @@
1
1
 
2
+ 0.2.1 / 2012-06-11
3
+ ==================
4
+
5
+ * fix doc asset links
6
+ * generate docs
7
+ * comment typos
8
+ * doc website header
9
+ * readme
10
+ * argv export default to using process.argv
11
+ * added travis support
12
+ * commentt program header
13
+ * fix bug that caused error on multiple calls to `program.colorize`
14
+
2
15
  0.2.0 / 2012-06-10
3
16
  ==================
4
17
 
package/README.md CHANGED
@@ -1,4 +1,151 @@
1
- electron
2
- ========
1
+ [![Build Status](https://secure.travis-ci.org/logicalparadox/electron.png?branch=master)](http://travis-ci.org/logicalparadox/electron)
3
2
 
4
- Event based CLI framework.
3
+ # Electron
4
+
5
+ > A simple command-line interface framework for [node.js](http://nodejs.org).
6
+
7
+ #### Features
8
+
9
+ - reimagined `process.argv` parsing utility
10
+ - framework for single or multiple command programs
11
+ - automatic `--help` command generation with multiple theming options
12
+ - built in cli coloring
13
+ - chainable api
14
+
15
+ ## Quick Start Guide
16
+
17
+ This "Quick Start Guide" and the full API reference can be found
18
+ on [electron's documentation website](http://alogicalparadox.com/electron).
19
+
20
+ #### Installation
21
+
22
+ The `electron` package is available through [npm](http://npmjs.org). It is recommended
23
+ that you add it to your project's `package.json`.
24
+
25
+ ```bash
26
+ npm install electron
27
+ ```
28
+
29
+ #### Parsing Arguments
30
+
31
+ The argument parsing utility can be used independently of the program
32
+ framework. Just pass the `process.argv` from any node modules and your
33
+ ready to go.
34
+
35
+ The following command execution...
36
+
37
+ ```bash
38
+ $ node cli.js build --minify --out saved.min.js
39
+ ```
40
+
41
+ Could be captured as so...
42
+
43
+ ```javascript
44
+ var argv = require('electron').argv();
45
+
46
+ // objects
47
+ argv.commands; // [ 'build' ]
48
+ argv.modes; // [ 'minify' ]
49
+ argv.params; // { out: 'saved.min.js' }
50
+
51
+ // helpers
52
+ argv.command('build'); // true
53
+ argv.mode('m', 'minify'); // true
54
+ argv.param('o', 'out'); // 'saved.min.js'
55
+ ```
56
+
57
+ Recommend reading the "Argument Parsing Utility" section of the
58
+ [documentation](http://alogicalpardox.com/electron)
59
+ to learn about the methodologies and specifics of each of the helpers.
60
+
61
+ #### Your First Program
62
+
63
+ To construct your first program, simply execute the electron export
64
+ with a parameter of the namespace you wish to use for your program.
65
+ Then proceed to define your settings and commands.
66
+
67
+ ```javascript
68
+ var myApp = require('../lib/myapp')
69
+ , program = require('electron')('myapp');
70
+
71
+ /**
72
+ * Define your program settings
73
+ */
74
+
75
+ program
76
+ .name('My Cool App')
77
+ .desc('http://docs.mycoolapp.com')
78
+ .version(myApp.version);
79
+
80
+ /**
81
+ * Define your first command
82
+ */
83
+
84
+ program
85
+ .command('build')
86
+ .desc('start a build task')
87
+ .option('-m, --minify', 'flag to set enable minification')
88
+ .option('-o, --out [file.js]', 'name of output file')
89
+ .action(function (argv) {
90
+ var minify = argv.mode('m', 'minify')
91
+ , savefile = argv.param('o', 'out')
92
+ , cwd = argv.cwd;
93
+
94
+ program.colorize();
95
+ console.log('Welcome to myApp'.gray + myApp.version);
96
+ console.log('It works if it ends with '.gray + 'myApp ' + 'ok'.green);
97
+ // etc...
98
+ });
99
+
100
+ /**
101
+ * Parse argv and execute respective command
102
+ */
103
+
104
+ program.parse();
105
+ ```
106
+
107
+ Your `-h, --help` and `-v, --version` will be generated for you automatically.
108
+
109
+ Recommend reading the "Program Framework" and "Constructing Commands" sections
110
+ of the [documentation](http://alogicalpardox.com/electron)
111
+ to learn about all of the available chainable commands and theming options
112
+ available to construct your programs.
113
+
114
+ ## Tests
115
+
116
+ Tests are writting in [Mocha](http://github.com/visionmedia/mocha) using
117
+ the [Chai](http://chaijs.com) `should` BDD assertion library. To make sure you
118
+ have that installed, clone this repo, install dependacies using `npm install`.
119
+
120
+ $ npm test
121
+
122
+ ## Contributors
123
+
124
+ Interested in contributing? Fork to get started. Contact [@logicalparadox](http://github.com/logicalparadox)
125
+ if you are interested in being regular contributor.
126
+
127
+ * Jake Luer ([@logicalparadox](http://github.com/logicalparadox))
128
+
129
+ ## License
130
+
131
+ (The MIT License)
132
+
133
+ Copyright (c) 2012 Jake Luer <jake@alogicalparadox.com>
134
+
135
+ Permission is hereby granted, free of charge, to any person obtaining a copy
136
+ of this software and associated documentation files (the "Software"), to deal
137
+ in the Software without restriction, including without limitation the rights
138
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
139
+ copies of the Software, and to permit persons to whom the Software is
140
+ furnished to do so, subject to the following conditions:
141
+
142
+ The above copyright notice and this permission notice shall be included in
143
+ all copies or substantial portions of the Software.
144
+
145
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
146
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
147
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
148
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
149
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
150
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
151
+ THE SOFTWARE.
@@ -11,7 +11,7 @@
11
11
  module.exports = Args;
12
12
 
13
13
  /**
14
- * ## Argument Parsing
14
+ * ## Argument Parsing Utility
15
15
  *
16
16
  * The electron argument parser takes the node.js standard
17
17
  * `process.argv` array and constructs an object with helpers
@@ -30,8 +30,8 @@ module.exports = Args;
30
30
  * ##### Commands
31
31
  *
32
32
  * Commands are the simplest of arguments. They are any arguments
33
- * that are listed to that do not start with the `-` prefix. Essentially,
34
- * they are a list of keys.
33
+ * that are listed to that do not start with the `-` or `--` prefix.
34
+ * Essentially, they are a list of keys.
35
35
  *
36
36
  * // $ node cli.js hello universe
37
37
  * argv.commands === [ 'hello', 'universe' ];
@@ -58,7 +58,7 @@ module.exports = Args;
58
58
  * , w: 'now'
59
59
  * };
60
60
  *
61
- * @header Argument Parsing
61
+ * @header Argument Parsing Utility
62
62
  */
63
63
 
64
64
  function Args (args) {
@@ -56,7 +56,28 @@ module.exports = Program;
56
56
  /**
57
57
  * ## Program Framework
58
58
  *
59
+ * The primary export of the electron module is a function
60
+ * that composes a new program framework. The returned
61
+ * `program` is a chainable api that allow you to change
62
+ * settings, define commands, and start launch the program.
59
63
  *
64
+ * The primary argument provided on construction is the base
65
+ * name used through the help documentation. In a majority of
66
+ * of cases, this would be the command executed from your terminal
67
+ * used launch the program.
68
+ *
69
+ * In the case of scripts with the header of `#!/usr/bin/env node`,
70
+ * you should use a variant of the following.
71
+ *
72
+ * var program = electron('microscope');
73
+ *
74
+ * If you are however launching your program from a `.js` file,
75
+ * the recommended construction pattern is the following.
76
+ *
77
+ * var program = electrong('node microscope.js');
78
+ *
79
+ * You can then chain any of the following commands to further
80
+ * define your application and commands.
60
81
  *
61
82
  * @header Program Framework
62
83
  */
@@ -69,6 +90,7 @@ function Program (base, opts) {
69
90
 
70
91
  Drip.call(this, { delimeter: ' ' });
71
92
  this.commands = [];
93
+ this._colorized = false;
72
94
  this.opts = defaults(opts || {}, {
73
95
  useColors: istty
74
96
  , version: null
@@ -415,6 +437,7 @@ Program.prototype.theme = function (name, spec) {
415
437
  * Just in case, if the current program is not running as a TTY,
416
438
  * no string changes will be made.
417
439
  *
440
+ * program.colorize();
418
441
  * console.log('hello universe'.green);
419
442
  *
420
443
  * ##### Colors
@@ -432,6 +455,7 @@ Program.prototype.theme = function (name, spec) {
432
455
  */
433
456
 
434
457
  Program.prototype.colorize = function (noColors) {
458
+ if (this._colorized) return this;
435
459
  var self = this
436
460
  , colors = {
437
461
  'red': 31
@@ -449,9 +473,13 @@ Program.prototype.colorize = function (noColors) {
449
473
  { get: function () {
450
474
  if (noColors || !self.opts.useColors) return this;
451
475
  return '\033[' + colors[color] + 'm' + this + '\033[0m';
452
- }
476
+ }
477
+ , configurable: true
453
478
  });
454
479
  });
480
+
481
+ this._colorized = true;
482
+ return this;
455
483
  };
456
484
 
457
485
  /*!
package/lib/electron.js CHANGED
@@ -34,6 +34,7 @@ exports.version = '0.2.0';
34
34
  */
35
35
 
36
36
  exports.argv = function (args) {
37
+ args = args || process.argv;
37
38
  var argv = new Args(args);
38
39
  return argv;
39
40
  };
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "author": "Jake Luer <jake@alogicalparadox.com>",
3
3
  "name": "electron",
4
- "description": "Event-based tiny CLI famework.",
5
- "version": "0.2.0",
4
+ "description": "A simple command-line interface framework for node.js.",
5
+ "keywords": [ "cli", "command", "option", "parser", "argv" ],
6
+ "homepage": "http://alogicalparadox.com/electron",
7
+ "license": "MIT",
8
+ "version": "0.2.1",
6
9
  "repository": {
7
10
  "type": "git",
8
11
  "url": "git://github.com/logicalparadox/electron.git"
@@ -1,30 +0,0 @@
1
- {
2
- "locals": {
3
- "title": "Electron"
4
- }
5
-
6
- , "plugins": [
7
- { "name": "code"
8
- , "files": [
9
- { "name": "index"
10
- , "title": "Electron Argument Parsing"
11
- , "file": "../../lib/electron/args.js"
12
- , "description": ":)"
13
- , "template": "index"
14
- , "render-file": false }
15
- , { "name": "index"
16
- , "title": "Electron Program Framework"
17
- , "file": "../../lib/electron/program.js"
18
- , "description": ":)"
19
- , "template": "index"
20
- , "render-file": false }
21
- , { "name": "index"
22
- , "title": "Electron Command Construction"
23
- , "file": "../../lib/electron/command.js"
24
- , "description": ":)"
25
- , "template": "index"
26
- , "render-file": false }
27
- ]
28
- }
29
- ]
30
- }
@@ -1,19 +0,0 @@
1
- ---
2
- title: Electron
3
- ---
4
-
5
- > A tiny cli framework for node.js.
6
-
7
- ## Features
8
-
9
- - tbd
10
-
11
- ## Installation
12
-
13
- ##### Node
14
-
15
- `electron` package is available through [npm](http://npmjs.org).
16
-
17
- ```bash
18
- npm install electron
19
- ```