-
Notifications
You must be signed in to change notification settings - Fork 115
New Command Line Interface
[PROPOSAL]
This is not yet implemented! See #51.
- simple
- short (but readable)
- full access to component options
- “just works” without parameters
In particular, this means:
- support for tweaking all public options of
- scanners
- filters
- encoders
- when no scanner is given, guess the language (file name extension, shebang line,
file
, …) - when no encoder is given, select based on output (tty for terminal, pipe for HTML page, filename based on extension like
convert
)
It should also have a short, easy-to-read help.
Should print version and help.
I like the subcommand approach.
[DONE] coderay [highlight] [sourcefile (or stdin) [targetfile (or stdout)]]
– highlight, standard operation
[LATER] coderay filter
– easy in-place filtering
[DONE] coderay stylesheet
– printing of stylesheets
[DONE] coderay list [{scanners,filters,encoders}]
– lists all components (of given type)
[DONE] coderay help [command]
– prints help (about command
)
[DONE] coderay commands
– prints list of available commands
[DONE] coderay --version
– prints version
[LATER] coderay server
– file system presented by CodeRay (automatic higlighting)?
Components, especially encoders, have options. For example, you may want to use a different color style for your HTML output.
Options come in several flavours:
- flags (no value, just given or not given, prefix with “no” to unset)
- choices (several possible values, choose from a list, one of them is the default)
- numbers
- lists
- arbitrary strings
Possible syntax:
coderay [-lang][:options] sourcefile [-filter[:options]] [-format][:options] targetfile
, where options
have the following form:
options ::= option ( , option )*
option ::= ( flag | noflag | parameter=value | parameter="value" )
Notes:
- Filters and encoders share a namespace. In fact, filters are encoders.
[DONE] coderay source.py
: Uses Python scanner (based on filename) and Terminal encoder (because STDOUT is tty).
[DONE] coderay Rakefile > outfile
: Uses Ruby scanner (based on filename) and HTML Page encoder (because STDOUT is not tty), and prints a warning about the automatic selection of the encoder.
[DONE] coderay ruby.h ruby.h.json
: Uses C scanner and JSON Page encoder (based on filenames).
[LATER] coderay < ruby.h
or cat ruby.h | coderay
: Guesses file type (hopefully C) and uses Terminal encoder.
…has to be defined before the input file.
[DONE] coderay -yaml
: Interactive highlighting for YAML.
[DONE] coderay -ruby example.jpg
: Uses Ruby scanner (ignoring the file extension), outputs to terminal.
…has to be defined after the input file or after the input type.
[DONE] coderay sample.html -loc
: Uses the Lines of Code encoder, outputs to the terminal.
[DONE] coderay sample.html -loc foo.lines
: Uses the Lines of Code encoder, outputs to file.
[DONE] coderay -ruby example.jpg -div
: Uses Ruby scanner, outputs HTML code to terminal.
[DONE] coderay -ruby example.jpg -div foo.xml
: Uses Ruby scanner, outputs HTML code to the file.
[DONE] coderay -diff -div
: Highlights Diff format from STDIN to HTML code with inlined styles.
[DONE] coderay -diff -div log.txt
: Waits for input, highlights Diff to HTML into the file.
svn diff | coderay -diff:highlight_content
: Uses Diff scanner with :highlight_content
option.
coderay :highlight_content some.diff
: the same
coderay index.php -page:title="My Glorious PHP Script" highlighted.html
: Uses HTML Page encoder with the title of the document set to My Glorious PHP Script.
coderay index.php -div:css=class:hint=info
: Uses HTML DIV encoder, but with CSS classes instead of inline styles, and info hints.
[LATER] coderay . project.html
: Highlight all source files inside the current directory into a single HTML file.
[LATER] coderay script.rb -remove_comments script.rb
: Uses the comment_filter
filter, and writes the filtered result back to script.rb
(no encoder for .rb
found, so it uses Plaintext.)
[LATER] coderay filter -remove_comments script.rb
: Same as above, but sure to write back into sourcefile as Plaintext.
[LATER] find . -name '*.{rb,rake,js}' -exec coderay filter -remove_comments -add_header:text="(c) 2010 murphy":autocomment {}\;
: Prepare a project for distribution, removing comments and adding copyright notices on top (using the appropriate comment syntax for the source file).
[LATER] coderay -json data -tabs:width=8 -page:style=alpha
: Uses JSON scanner for the file data
, applies Tabs filter with a :width
of 8 spaces, and produces the output with the HTML Page encoder using the Alpha style.
[LATER] coderay filter -tabs:width=2 .
: Replace tabs with 2 spaces in all source files inside the current directory.
[DONE] coderay stylesheet
: Prints the default stylesheet used for the HTML encoder.
[DONE] coderay stylesheet alpha
: Prints the Alpha stylesheet.