Giter Site home page Giter Site logo

phantom-args's Introduction

phantom-args

Command line argument utility for PhantomJS

Build Status

Features

  • Specify command line argument options in config.json
  • Found arguments (and values) are returned in nicely formatted JSON object
  • Get on with writing your code, without the hassle of having to handle all argument options

Usage

  • First, specity what arguments you want your app to handle in the config.json file. test1 is the unique identifier for that specific option, type can either be set to option or param (param will provide the subsequent argument as the parameter passed). Multiple "flags" for the processor to find can be specified in the array, and an additional "required" option can also be specified (this feature might be deprecated).
		{
			"test1":{
				"type":"option",
				"flag":['-t','--test1'],
				"required":false
			},
			"test2":{
				"type":"param",
				"flag":['--test2'],
				"required":true
			},
			"test3":{
				"type":"option",
				"flag":['--test3'],
				"required":false
			}
		}
  • Easy to use! Including the processor in a PhantomJS script requires just three simple lines of code:
    var scriptArgs = require('system').args.slice(1);
    phantom.injectJs('args.js');
    var argResult = processArgs(scriptArgs);
  • Arguments returned in an easy-to-use JSON object. For example, if app.js is started with phantomjs app.js --test2 testText --test1, processArgs will return the following object. value is automatically set to null if the argument is of type option.
		{
			"test1":{
				"required":false,
				"found":true,
				"value":null
			},
			"test2":{
				"required":true,
				"found":true,
				"value":"testText"
			},
			"test3":{
				"required":false,
				"found":false,
				"value":null
			}
		}
  • For more tutorials, take a look at the code examples, as well as the tests

Coming soon

  • Similar argument processor for Node.js applications (as an npm module)
  • Possibly an all-in-one project

Developers

If you wish to add features to phantom-args, fork me and send a pull request when completed. Before submitting a pull request, run the test suite for the project by running npm test. NOTE: To run the tests, Node.js (0.6.x or 0.8.x, not tested on 0.9.x), PhantomJS 1.6 or greater, npm 1.0.x, and jasmine-node must be installed. Tests are written in the Jasmine BDD testing framework.

phantom-args's People

Contributors

rahulsmehta avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.