Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
Fix issue #31
Browse files Browse the repository at this point in the history
The syntax is still fairly constrained - but on purpose in order to keep
the `--` the definitive EOA marker. The reason `[--] ARGS` is allowed,
despite not being "correct" is for compatibilites sake.
  • Loading branch information
felixSchl committed May 13, 2016
1 parent 7178f5f commit 394dcf5
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 18 deletions.
3 changes: 1 addition & 2 deletions examples/git/add.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
require('shelljs/global');

// XXX: -- should be [--]. See #31
module.exports = (argv) => {
const args = require('../..').run(`
usage: git add [options] -- <pathspec>...
usage: git add [options] [--] <pathspec>...
Options:
-n, --dry-run dry run
Expand Down
3 changes: 1 addition & 2 deletions examples/git/bisect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ const _ = require('lodash');

// The git-bisect help text is a bit unconventional and requires some special
// treatment for prepartion
// XXX: -- should be [--]. See #31
module.exports = (argv) => {

const help = `
usage: git bisect [help|start|bad|good|skip|next|reset|visualize|replay|log|run] [<args>...]
git bisect help
print this long help message.
git bisect start [--no-checkout] [<bad> [<good>...]] -- [<pathspec>...]
git bisect start [--no-checkout] [<bad> [<good>...]] [--] [<pathspec>...]
reset bisect state and start bisection.
git bisect bad [<rev>]
mark <rev> a known-bad revision.
Expand Down
1 change: 0 additions & 1 deletion examples/git/checkout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require('shelljs/global');

// XXX: -- should be [--]. See #31
module.exports = (argv) => {
const args = require('../..').run(`
Expand Down
3 changes: 1 addition & 2 deletions examples/git/clone.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require('shelljs/global');

// XXX: -- should be [--]. See #31
module.exports = (argv) => {
const args = require('../..').run(`
usage: git clone [options] -- <repo> [<dir>]
usage: git clone [options] [--] <repo> [<dir>]
options:
-v, --verbose be more verbose
Expand Down
3 changes: 1 addition & 2 deletions examples/git/commit.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require('shelljs/global');

// XXX: -- should be [--]. See #31
module.exports = (argv) => {
const args = require('../..').run(`
usage: git commit [options] -- <pathspec>...
usage: git commit [options] [--] <pathspec>...
options:
-q, --quiet suppress summary after successful commit
Expand Down
3 changes: 1 addition & 2 deletions examples/git/diff.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
require('shelljs/global');

// XXX: -- should be [--]. See #31
module.exports = (argv) => {
const args = require('../..').run(`
usage: git diff [<options>] [<commit> [<commit>]] -- [<path>...]
usage: git diff [<options>] [<commit> [<commit>]] [--] [<path>...]
`, { argv: argv, smartOptions: true });

echo(args);
Expand Down
1 change: 0 additions & 1 deletion examples/git/fetch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require('shelljs/global');

// XXX: -- should be [--]. See #31
// Note: `[<options>]` has been edited to `[options]`.
module.exports = (argv) => {
const args = require('../..').run(`
Expand Down
4 changes: 1 addition & 3 deletions examples/git/grep.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require('shelljs/global');

// XXX: -- should be [--]. See #31
// original: usage: git grep [options] [-e] <pattern> [<rev>...] [[--] <path>...]
module.exports = (argv) => {
const args = require('../..').run(`
usage: git grep [options] <pattern> [<rev>...] -- [<path>...]
usage: git grep [options] <pattern> [<rev>...] [[--] <path>...]
options:
--cached search in index instead of in the work tree
Expand Down
19 changes: 16 additions & 3 deletions src/Language/Docopt/Parser/Usage.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Language.Docopt.Parser.Usage (
) where

import Prelude
import Debug.Trace
import Language.Docopt.Parser.Lexer as L
import Language.Docopt.Parser.Usage.Option as O
import Language.Docopt.Parser.Usage.Usage as U
Expand All @@ -25,7 +26,7 @@ import Language.Docopt.Parser.Usage.Argument (Argument(..))
import Language.Docopt.Parser.Usage.Usage (Usage(..))
import Text.Parsing.Parser (ParseError) as P
import Text.Parsing.Parser.Combinators (try, optional, choice, sepBy1, between,
lookAhead) as P
optionMaybe, lookAhead) as P
import Text.Parsing.Parser.Combinators ((<?>), (<??>))
import Text.Parsing.Parser.Pos (Position(Position)) as P

Expand Down Expand Up @@ -72,9 +73,12 @@ usageParser smartOpts = do
(many $ P.try $ moreIndented *> elem) `P.sepBy1` L.vbar
eoa <- P.choice [
P.try $ do
moreIndented *> L.doubleDash
P.optional do
maybeInParens do
maybeInParens do
L.doubleDash
many elem
many elem
many elem
return $ Just EOA
, (do
L.eof <|> (P.lookAhead $ lessIndented <|> sameIndent)
Expand All @@ -92,6 +96,15 @@ usageParser smartOpts = do
(\as -> as ++ (singleton e))
xs

maybeInParens p = do
Tuple close v <- moreIndented *> do
Tuple
<$> (P.optionMaybe $ P.choice [ L.lparen *> return L.rparen
, L.lsquare *> return L.rsquare ])
<*> p
fromMaybe (pure unit) close
return v

elem :: L.TokenParser Argument
elem = defer \_ -> do
P.choice $ P.try <$>
Expand Down
19 changes: 19 additions & 0 deletions testcases.docopt
Original file line number Diff line number Diff line change
Expand Up @@ -2721,3 +2721,22 @@ $ prog/s -b 2000

$ prog/s -a 1000 -b 2000
{"-a": [1000], "-b": [2000]}

# Fix issue #31
# The syntax is still fairly constrained - but on purpose in order to keep
# the `--` the definitive EOA marker. The reason `[--] ARGS` is allowed, despite
# not being "correct" is for compatibilites sake.

r"""
Usage: foo [--] <pathspec>...
"""

$ prog
{"--": []}

r"""
Usage: foo [[--] ARGS]
"""

$ prog
{"--": []}

0 comments on commit 394dcf5

Please sign in to comment.