Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

simonecorsi/string-to-argv.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Parse String to ARGV as object

Parse a string of a unix-like command line and parse it into a more usable Object

Usage in node

  let Parser = require('string-to-argv.js')
  let parsed = new Parser('cmd -z -c -v -flag1 123 -p -f test --depth=0 -s --string=noquotes --flagstring="with spaces" source/ dest/')
  // @return
  {
    raw: 'cmd -z -c -v -flag1 123 -p -f test --depth=0 -s --string=noquotes --flagstring="with spaces" source/ dest/',
    command: 'cmd',
    _: [ 'source/', 'dest/' ],
    z: true,
    c: true,
    v: true,
    flag1: '123',
    p: true,
    f: 'test',
    depth: '0',
    s: true,
    string: 'noquotes',
    flagstring: 'with spaces'
  }

##Usage in Browser

  <script src="node_modules/string-to-argv.js/dist/Parser.js"></script>
  <script>
    var Parser = new Parser(/* ... */)
    // ...
  </script>

Know Issue

  • nesting quotes in stringed flag not implemented.

##Error

  try{
    let parsed = new Parser() // or empty string
  } catch(e) {
    console.log(e.message)
  }
  //> 'Parser: command provided is empty.'

###Dev

Source must be compiled to use with es2015

Run npm install or yarn install

Build with npm run build

Test with npm test

About

Parse a command line String into a more usable JS Object, used in Kirkhammetz/termly.js

Resources

Stars

Watchers

Forks

Packages

No packages published