CARVIEW |
Select Language
HTTP/2 200
date: Fri, 18 Jul 2025 22:15:36 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-robots-tag: none
etag: W/"0a0808653e79864b0c53f883337e2ede"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=m5SNh%2BujOdWZMdAux6f0Tmzs0tMZ4v0PA4DNJefzd7gQdp9NipJJJ%2BVHcH6toIeZXgrVHrvKmeM4GGQFcazwAeikR3%2BHKQ%2FskDvw3hXTRJm7Pg1ykUok3IshG9TOEJFBp%2B0GK9CgYV0FCyJoMvOE7kDa7k3ov2dkXxbejHp6yeU9jEjxV48F8bW3J7G0pMWceypsSLwQ8JnZYycTt8uD6lEKw6xnt3U7yA6fon0n3RsSIR%2FjtAwwa1BLo0505S9Vski0s6QYrFLkYA%2BbNR2f7g%3D%3D--xgDMCmmHZTy6Hm%2FM--KXWuxuX13HZzepmPkrrx5A%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.38648058.1752876936; Path=/; Domain=github.com; Expires=Sat, 18 Jul 2026 22:15:36 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sat, 18 Jul 2026 22:15:36 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: DE12:1BD1FC:1CBBBE:263C08:687AC788
Home · docopt/docopts Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 54
Home
Sylvain303 edited this page Sep 21, 2021
·
8 revisions
The wiki pages are used for discussion. Feel free to contribute.
docopts
documentation lives in README
EBNF like prototype:
(*
here is grammar definition for docopt language, in EBNF.
Only the "Usage: prog" is mandatory
*)
Docopt = [ Prologue ]
, Usage
, [ Free_text ]
, [ Options ]
, [ Free_text ]
;
(*
Prologue can be used to introduce the program.
Matching USAGE leaves the Prologue.
*)
Prologue = Line_of_text, NEWLINE | { Prologue } ;
NEWLINE = ? all line ending char combination ? ;
Line_of_text = ALL_CHARACTERS - USAGE ;
ALL_CHARACTERS = ? all visible characters ? ;
USAGE = ? "Usage:" case insensitive ? ;
Usage = USAGE , First_Program_Usage | { Program_Usage } ;
First_Program_Usage = PROG_NAME , [ Expr ] ;
(*
PROG_NAME is catched at first definition and stay the same literal for all the parsing
Program_Usage can be break multi-line: Indent + PROG_NAME will start a new Program_Usage
Usage: ./my_program.sh [-h] [--lovely-option] FILENAME
./my_program.sh another LINE OF --usage
my_program will continue [--above] <usage-definition>
PROG_NAME on first usage parsing it becomes: "./my_program.sh"
*)
PROG_NAME = ? any non space characters ? ;
Program_Usage = Indent , PROG_NAME [ Expr ] ;
Indent = ? Long_space at the beginning of the line ? ;
Long_space = " " , { ' ' } | '\t' , { '\t' } ;
Expr = Seq , { '|' , Seq } ;
Seq = Atom , [ "..." ] ;
Atom = '(' , Expr , ')'
| '[' , Expr , ']'
| "options"
| Long_def
| Shorts_option
| Argument
| Command
| '-' | "--" (* single-dash and double-dash *)
;
Shorts_option = Short | Short , Argument ;
Long_def = Long | Long , Argument | Long , '=' , Argument ;
Long = '--' , Chars , Chars { '_' | '-' | Chars } ;
Short = '-' , Chars ;
Chars = Lowercase | Capital | Digit ;
Lowercase = ? lowercase latin1 letters ? ;
Capital = ? Uppercase latin1 letters ? ;
Digit = ? numbers 0 at 9 ? ;
Argument = Angle_Argument | Capital_Argument ;
Angle_Argument = '<' , Lowercase , { Lowercase | '_' | '-' | Digit } , '>' ;
Capital_Argument = Capital , { Capital | '_' | Digit } ;
Options = OPTIONS_KEYWORD , Options_Help { Options_Help } ;
OPTIONS_KEYWORD = ? "Options:" case insensitive ? ;
Options_Help = Indent , Option_Flag , Option_description ;
Option_Flag = ( Short_def | Long_def ) , [ ( " " | "," ) , Option_Flag ] ;
Short_def = Short | Short Argument ;
Option_description = Long_space , Description_text , [ Default_value ] ;
Description_text = ALL_CHARACTERS - Default_value ;
(*
Value_for_default:
']' can be given for default that way: [default: "]"]
double quote can be escaped too: [default: "{ \"I love \" : \"JSON\" }"]
emtpy string: [default: ""]
This is not done that way in python:
https://github.com/docopt/docopt/blob/20b9c4ffec71d17cee9fd963238c8ec240905b65/docopt.py#L200
first value found for "default:" note the first space is not part of the value.
matched = re.findall('\[default: (.*)\]', description, flags=re.I)
value = matched[0] if matched else None
*)
Default_value = '[' , "default:" , ' ' , Value_for_default , ']' ;
Value_for_default = string
| ALL_CHARACTERS - ']'
;
string = '"' , { ALL_CHARACTERS - '"' | escaped_double_quote } , '"' ;
escaped_double_quote = '\' , '"' ;
(*
Free_text allow to add help information in a section like message, which is eaten by the parser.
Free_text could be extend and or parsed on grammar extension, new defined sections for example:
Arguments:
FILENAME Inputfile
COUNTER Number of time to repeat the action.
etc.
Howto:
Some information, bla, bla
Indent is not mandatory, it's free.
Usage: <== this will fail? or not? as usage is already parsed. (failure on python's version 0.6.1)
*)
Free_text = ALL_CHARACTERS - USAGE - OPTIONS_KEYWORD , NEWLINE | { Free_text } ;
# auto extract the Usage string from the top shell script comment
# ie: help=$(sed -n -e '/^# Usage:/,/^$/ s/^# \?//p' < $0)
help_string=$(docopt_get_help_string $0)
# if the option as multiples values, you can get it into an array
array_opt=( $(docopt_get_values args --multiple-time) )
See python/docopt
Source: naval_fate.sh
naval_fate.sh ship Guardian move 100 150 --speed=15
returned $parsed string to be evaluated:
declare -A arguments
arguments['--drifting']=false
arguments['mine']=false
arguments['--help']=false
arguments['move']=true
arguments['--moored']=false
arguments['new']=false
arguments['--speed']='15'
arguments['remove']=false
arguments['--version']=false
arguments['set']=false
arguments['<name>']='Guardian'
arguments['ship']=true
arguments['<x>']='100'
arguments['shoot']=false
arguments['<y>']='150'
- repeatable options with filename with space inside, will not be easily split on $IFS, but old fake nested array is still available or use an helper
eval "$(docopt_get_eval_array args FILE myarray)"
API_proposal.md Was issue #7 for the discussion and proposing your changes.
You can’t perform that action at this time.