Skip to content

Commit

Permalink
prepare for npm
Browse files Browse the repository at this point in the history
  • Loading branch information
shinout committed Apr 28, 2011
1 parent c1c4ae3 commit 56ac9f7
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ArgParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,7 @@ ArgParser.prototype.parse = function(arr) {
});
}

/* version */
ArgParser.version = '0.0.1';

module.exports = ArgParser;
22 changes: 22 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2011 SHIN Suzuki <shinout310@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51 changes: 51 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
argparser v0.0.1
==================
[Node.js] コマンドライン引数、オプション解析

変更履歴

----------------
* [0.0.1]: リリース

概要
----------------
### インストール方法 ###
git clone git://github.com/shinout/argparser.git

または

npm install argparser

### 使い方 ###
const ArgParser = require('argparser');

/* シンプルな使い方 */
/* node hoge.js --long-var -s foo bar */
var parser = new ArgParser().parse();
parser.getArgs(); // [foo, var]
parser.getOptions(); // {long-var: true, s: true}


/* 引数つきオプションを指定 */
/* node hoge.js piyo foo -h --var-with-val 392 bar */
var parser = new ArgParser();
parser.addValueOptions(['var-with-val']);
parser.parse();
parser.getArgs(); // [piyo, foo, var]
parser.getOptions(); // {h: true, var-with-val: 392}


/* 配列を与えて解析 */
var parser = new ArgParser();
parser.addValueOptions(['encoding', 'm', 'aaa']);
parser.parse(['-m', 110, '--encoding', 'utf-8', 'index.html']);
parser.getArgs(); // [index.html]
parser.getOptions(); // {encoding: utf-8, m: 100, aaa: false}


/* 引数なしオプションを指定 */
parser.addOptions(['-h', '-t']);
parser.addValueOptions(['encoding', 'm']);
parser.parse(['-h', 'hoge', '--encoding', 'utf-8', 'index.html']);
parser.getArgs(); // [hoge, index.html]
parser.getOptions(); // {h: true, encoding: true, m: false}
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
argparser v0.0.1
==================
[Node.js] parse commandline-args and options

SYNOPSIS
-------------
/* simplest use */
Change Log

----------------
* [0.0.1]: Release

Overview
----------------
### Installation ###
git clone git://github.com/shinout/argparser.git

OR

npm install argparser

### Usage ###
const ArgParser = require('argparser');

/* the simplest use */
/* node hoge.js --long-var -s foo bar */
var parser = new ArgParser().parse();
parser.getArgs(); // [foo, var]
Expand Down Expand Up @@ -33,4 +49,3 @@ SYNOPSIS
parser.parse(['-h', 'hoge', '--encoding', 'utf-8', 'index.html']);
parser.getArgs(); // [hoge, index.html]
parser.getOptions(); // {h: true, encoding: true, m: false}

18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "argparser"
, "version": "0.0.1"
, "description": "object to parse commandline-args and options."
, "tags": ["getopt", "arguments", "option", "getopts", "command"]
, "author": "SHIN Suzuki <shinout310@gmail.com>"
, "repository":
{ "type": "git"
, "url": "https://github.com/shinout/argparser.git"
}
, "bugs": {"web": "https://github.com/shinout/argparser/issues" }
, "licences":
[ { "type": "MIT"
, "url": "https://github.com/shinout/argparser/raw/master/LICENCE"
}
]
, "main": "./ArgParser.js"
}
54 changes: 54 additions & 0 deletions scripts/README.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
argparser v${version}
==================
[Node.js] ${description}

${changelog}

----------------
<< for (var i in changeLogs) { >>
* [${i}]: ${changeLogs[i]}
<< } >>

${overview}
----------------
### ${install} ###
git clone git://github.com/shinout/argparser.git

${_OR}

npm install argparser

### ${usage} ###
const ArgParser = require('argparser');

/* ${simplest_use} */
/* node hoge.js --long-var -s foo bar */
var parser = new ArgParser().parse();
parser.getArgs(); // [foo, var]
parser.getOptions(); // {long-var: true, s: true}


/* ${with_value} */
/* node hoge.js piyo foo -h --var-with-val 392 bar */
var parser = new ArgParser();
parser.addValueOptions(['var-with-val']);
parser.parse();
parser.getArgs(); // [piyo, foo, var]
parser.getOptions(); // {h: true, var-with-val: 392}


/* ${parse_array} */
var parser = new ArgParser();
parser.addValueOptions(['encoding', 'm', 'aaa']);
parser.parse(['-m', 110, '--encoding', 'utf-8', 'index.html']);
parser.getArgs(); // [index.html]
parser.getOptions(); // {encoding: utf-8, m: 100, aaa: false}


/* ${non_val} */
parser.addOptions(['-h', '-t']);
parser.addValueOptions(['encoding', 'm']);
parser.parse(['-h', 'hoge', '--encoding', 'utf-8', 'index.html']);
parser.getArgs(); // [hoge, index.html]
parser.getOptions(); // {h: true, encoding: true, m: false}

18 changes: 18 additions & 0 deletions scripts/en.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ changeLogs :
{ "0.0.1" : "Release"
}

, changelog : 'Change Log'
, _OR : 'OR'
, description : 'parse commandline-args and options'
, install : 'Installation'
, overview : 'Overview'
, usage : 'Usage'



, simplest_use : 'the simplest use'
, with_value : 'set options with value'
, parse_array : 'parse array'
, non_val : 'set non-value options'
}
18 changes: 18 additions & 0 deletions scripts/ja.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ changeLogs :
{ "0.0.1" : "リリース"
}

, changelog : '変更履歴'
, _OR : 'または'
, description : 'コマンドライン引数、オプション解析'
, install : 'インストール方法'
, overview : '概要'
, usage : '使い方'



, simplest_use : 'シンプルな使い方'
, with_value : '引数つきオプションを指定'
, parse_array : '配列を与えて解析'
, non_val : '引数なしオプションを指定'
}
18 changes: 18 additions & 0 deletions scripts/package.tpl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "argparser"
, "version": "${version}"
, "description": "object to parse commandline-args and options."
, "tags": ["getopt", "arguments", "option", "getopts", "command"]
, "author": "SHIN Suzuki <shinout310@gmail.com>"
, "repository":
{ "type": "git"
, "url": "https://github.com/shinout/argparser.git"
}
, "bugs": {"web": "https://github.com/shinout/argparser/issues" }
, "licences":
[ { "type": "MIT"
, "url": "https://github.com/shinout/argparser/raw/master/LICENCE"
}
]
, "main": "./ArgParser.js"
}
21 changes: 21 additions & 0 deletions scripts/umecob-command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var umecob = require("umecob");
var version = require("../ArgParser").version;
var tplfile = process.argv[2];
var datafile = process.argv[3];


umecob.start('f', function(p) {
p.tpl_id = __dirname + '/../' + p.tpl_id;
if (p.data_id) {
p.data_id = __dirname + '/../' + p.data_id;
}
else {
p.data = {};
}
});

umecob.compiler('scripts', umecob.Umecob.compiler('<','<','>','>'));
var result = umecob({use: "file", tpl_id: tplfile, data_id: datafile, attach: function(data) {
data.version = version
},sync: true});
process.stdout.write(result);
5 changes: 5 additions & 0 deletions scripts/updateinfo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
thisdir=$(dirname $0)
node ${thisdir}/umecob-command.js ${thisdir}/README.tpl.md ${thisdir}/en.lang > ${thisdir}/../README.md
node ${thisdir}/umecob-command.js ${thisdir}/README.tpl.md ${thisdir}/ja.lang > ${thisdir}/../README.ja.md
node ${thisdir}/umecob-command.js scripts/package.tpl.json > ${thisdir}/../package.json

0 comments on commit 56ac9f7

Please sign in to comment.