Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 5, 2020. It is now read-only.
/opt.jsPublic archive

Probably the sole command line option parser you'll ever need to...

NotificationsYou must be signed in to change notification settings

dcodeIO/opt.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opt.js

Probably the sole command line option parser you'll ever need tonpm install optjs Ctrl+C, Ctrl+V. Proof:

functionopt(argv){varopt={},arg,p;argv=Array.prototype.slice.call(argv||process.argv);for(vari=2;i<argv.length;i++)if(argv[i].charAt(0)=='-')((p=(arg=(""+argv.splice(i--,1)).replace(/^[\-]+/,'')).indexOf("="))>0?opt[arg.substring(0,p)]=arg.substring(p+1):opt[arg]=true);return{'node':argv[0],'script':argv[1],'argv':argv.slice(2),'opt':opt};}

Usage

varopt=require("optjs")();console.log(opt.node);// Path to node executableconsole.log(opt.script);// Path to the current scriptconsole.log(opt.opt);// Command line options as a hashconsole.log(opt.argv);// Remaining non-option arguments

Example

node somescript.js foo -a=1 -b --c="hello world" bar ----d

// Resultopt.node=="/path/to/node[.exe]"opt.script=="/path/to/somescript.js"opt.opt=={a:1,b:true,c:"hello world",d:true}opt.argv==["foo","bar"]

Full-featured test suite

#!/usr/bin/env nodeconsole.log(require("./opt.js")());

License

MIT

About

Probably the sole command line option parser you'll ever need to...

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp