Module: CTioga2::Commands
- Defined in:
- lib/ctioga2/commands/interpreter.rb,
lib/ctioga2/commands/type.rb,
lib/ctioga2/commands/groups.rb,
lib/ctioga2/commands/context.rb,
lib/ctioga2/commands/doc/doc.rb,
lib/ctioga2/commands/doc/man.rb,
lib/ctioga2/commands/strings.rb,
lib/ctioga2/commands/commands.rb,
lib/ctioga2/commands/doc/help.rb,
lib/ctioga2/commands/doc/html.rb,
lib/ctioga2/commands/function.rb,
lib/ctioga2/commands/arguments.rb,
lib/ctioga2/commands/variables.rb,
lib/ctioga2/commands/doc/markup.rb,
lib/ctioga2/commands/instruction.rb,
lib/ctioga2/commands/doc/wordwrap.rb,
lib/ctioga2/commands/parsers/file.rb,
lib/ctioga2/commands/general-types.rb,
lib/ctioga2/commands/general-commands.rb,
lib/ctioga2/commands/parsers/old-file.rb,
lib/ctioga2/commands/doc/introspection.rb,
lib/ctioga2/commands/general-functions.rb,
lib/ctioga2/commands/parsers/command-line.rb,
lib/ctioga2/commands/doc/documentation-commands.rb
Overview
This module contains the real core of ctioga2: a set of classes that implement the concept of commands. Each command translates into an action (of any kind).
Commands can be specified using several ways: either using command-line options/arguments or through a commands file.
Defined Under Namespace
Modules: Documentation, Parsers Classes: ArgumentNumberMismatch, Command, CommandArgument, CommandGroup, CommandOptionUnkown, CommandType, DoubleDefinition, Function, Instruction, Interpreter, InterpreterString, InvalidName, InvalidType, ParsingContext, RecursiveExpansion, UnknownCommand, UnterminatedString, Variables
Constant Summary collapse
- NameValidationRE =
A CommandGroup#id or Command#name should match this regular expression.
/^[a-z0-9-]+$/
- FileType =
A file name.
CmdType.new('file', :string, <<EOD) A file name. EOD
- TextType =
Plain text
CmdType.new('text', :string, <<EOD) Plain text. EOD
- DatasetType =
A series of datasets
CmdType.new('dataset', :string, <<EOD) One expandable dataset. EOD
- CommandsType =
Commands
CmdType.new('commands', :string, <<EOD) ctioga2 commands, such as the ones that could be found in command files. EOD
- BooleanType =
CmdType.new('boolean', :boolean, <<EOD) Yes or no. EOD
- FloatType =
CmdType.new('float', :float, <<EOD) A floating-point number. EOD
- FloatOrFalseType =
CmdType.new('float-or-false', { :type => :float, :shortcuts => {'none' => false }}, <<EOD) A floating-point number, or @none@. EOD
- FloatList =
CmdType.new('float-list', { :type => :array, :subtype => :float, :separator => /\s+|\s*,\s*/, :separator_out => " " }, <<EOD) A list of space-separated or comma-separated floating point numbers. EOD
- TextList =
CmdType.new('text-list', { :type => :array, :subtype => :string, :separator => /\s*,\s*/, :alternative_separator => /\s*\|\|\s*/, :separator_out => "," }, <<EOD) A list of comma-separated texts. If you must include a comma inside the texts, then use @||@ as a separator. EOD
- IntegerType =
CmdType.new('integer', :integer, <<EOD) An integer. EOD
- IntegerList =
CmdType.new('integer-list', { :type => :array, :subtype => :integer, :separator => /\s+|\s*,\s*/, :separator_out => " " }, <<EOD) A list of space-separated or comma-separated integers EOD
- PartialFloatRangeType =
CmdType.new('partial-float-range', :partial_float_range, <<EOD) A beginning:end range, where either of the endpoints can be ommitted. EOD
- FloatRangeType =
CmdType.new('float-range', :float_range, <<EOD) A beginning:end range. EOD
- StringOrRegexp =
CmdType.new('regexp', :string_or_regexp, <<EOD) A plain string or a regular expression (the latter being enclosed within /.../). EOD
- DataPointType =
Data-point. Unlike other types, this one needs to be processed afterwards, actually, since an access to a plotmaker object is necessary.
CmdType.new('data-point', :data_point, <<EOD) A point from an already-loaded Dataset. You have two ways to choose the point: * @@13@ takes the 13th point in the last dataset; * @0.2@ takes the point the closest to 20% of the dataset. If you need another dataset than the last one, give its number or named within brackets: @{-2}0.2@ is the point closest to the 20% of the one-before-last dataset. EOD
- LaTeXFontType =
A LaTeX font
CmdType.new('latex-font', :latex_font, <<EOD) A LaTeX font. @todo document ! EOD
- ColorMapType =
A color map
CmdType.new('colormap', :colormap, <<EOD) A Z color map. It takes the form @Color1--Color2--Color3...@. All colors can optionally be followed by a number. For instance, for @Red--Blue--Pink--Green@, the colors are evenly spaced. In the case @Red--Blue(0.1)--Pink(0.2)--Green@, the Blue to Pink strech is located between Z values 0.1 and 0.2. If a prefix @hls:@ or @wheel:@ is present, then linear interpolation is done in the HLS colorspace instead of the RGB one (the default). If a suffix @:sym:@_value_ is present, then the colormap is symmetric around that value. It is also possible to directly use a {type: color-set}, in which case eveything works as if the colors of the {type: color-set} had been given directly, without Z values. EOD
- StoredDatasetType =
A stored dataset.
CmdType.new('stored-dataset', :string, <<EOD) A dataset that has already been loaded. It is either: * A number, in which case it specifies the index inside the stack. 0 is the first on that was pushed onto the stack (the oldest dataset), 1 the second, -1 the last one, -2 the one before the last and so on. (it works just like Ruby's arrays). * The name of a named dataset. * @#@ followed by the id of a plot element EOD
- AxisType =
Something meant to be fed to PlotStyle#get_axis_style
CmdType.new('axis', :string, <<EOD) The name of the axis of a plot. It can be: * @left@, @top@, @bottom@ or @right@; * @x@, @xaxis@, @y@, @yaxis@, which return one of the above depending on the preferences of the current plot (see {command: xaxis} and {command: yaxis} to change them); * one of the named axes, such as the ones created by {command: new-zaxis}. EOD
- LabelType =
Something meant to be fed to PlotStyle#get_label_style
CmdType.new('label', :string, <<EOD) The name of an label. It can be: * @title@ to mean the current plot's title. * @axis_tick@ or @axis_ticks@ or simply @axis@, where @axis@ is a a valid {type: axis}. It designates the ticks of the named axis. * @axis_label@, same as above but targets the label of the named axis. EOD
- GeneralGroup =
General scope commands.
CmdGroup.new('general', "General commands", "General scope commands", 1000)
- CommandLineHelpOptions =
{ 'pager' => CmdArg.new('boolean') }
- CommandLineHelpCommand =
Display help on the command-line
Cmd.new("command-line-help", 'h', "--help", [ ], CommandLineHelpOptions) do |plotmaker, | plotmaker.interpreter.doc.display_command_line_help() exit end
- HelpOnCommand =
Display help on the command-line
Cmd.new("help-on", nil, "--help-on", [CmdArg.new('text') ]) do |plotmaker, cmd, | plotmaker.interpreter.doc.display_help_on(cmd, ) exit end
- PrintVersion =
Prints the version of ctioga2 used
Cmd.new("version", '-V', "--version", []) do |plotmaker| puts "This is ctioga2 version #{CTioga2::Version::version}" end
- RunCommandFile =
Includes a file
Cmd.new("include", '-f', "--file", [ CmdArg.new('file')], {'log' => CmdArg.new('boolean') } ) do |plotmaker, file, opts| # Work around bug on windows ! file = Utils::transcode_until_found(file) if opts['log'] tg = file.sub(/(\.ct2)?$/, '-log.txt') Log::log_to(tg, "ctioga2 version '#{CTioga2::Version::version}' starting at #{Time.now} to process file: #{file}") end plotmaker.interpreter.run_command_file(file) end
- EvalCommand =
Evaluate a series of commands.
Cmd.new("eval", '-e', "--eval", [ CmdArg.new('commands'), ]) do |plotmaker, string| plotmaker.interpreter.run_commands(string) end
- RunRubyFile =
Runs a ruby file
Cmd.new("ruby-run", nil, "--ruby-run", [ CmdArg.new('file')], {} ) do |plotmaker, file, opts| # Work around bug on windows ! file = Utils::transcode_until_found(file) Ruby::run_file(file) end
- SetCommand =
Evaluate a series of commands.
Cmd.new("set", nil, "--set", [ CmdArg.new('text'), CmdArg.new('text') ]) do |plotmaker, variable, value| plotmaker.interpreter.variables.define_variable(variable, value) end
- VerboseLogging =
Increases verbosity
Cmd.new("verbose", '-v', "--verbose", [ ]) do |plotmaker| CTioga2::Log::set_level(Logger::INFO) end
- Pause =
Cmd.new("pause", nil, "--pause", [ CmdArg.new('boolean') ]) do |plotmaker, val| plotmaker.pause_on_errors = val end
- DebugLogging =
Write debugging information.
todo this should be the place where a lot of customization of the debug output could go - including channels or things like that. To be seen later on…
Cmd.new("debug", nil, "--debug", [ ]) do |plotmaker| CTioga2::Log::set_level(Logger::DEBUG) end
- EchoCmd =
Prints the command-line used
Cmd.new("echo", nil, "--echo", [ ]) do |plotmaker| STDERR.puts "Command-line used: " STDERR.puts plotmaker.quoted_command_line end
- PrintInstructionsCmd =
Writes down the list of instruction run so far
Cmd.new("print-instructions", nil, "--print-instructions", [ ]) do |plotmaker| for ins in plotmaker.interpreter.instructions puts ins.to_s end end
- FuncEval =
Function.new("eval", "Evaluate Ruby code") do |pm, code| Ruby::run_code(code) end
- FuncPoint =
dataset functions
Function.new("point", "Get dataset point information") do |pm, what, spec, *rest| dataset = if rest.first pm.data_stack.stored_dataset(rest.first) else nil end point = Data::DataPoint::from_text(pm, spec, dataset) case what when "x", "X" point.x.to_s when "y", "Y" point.y.to_s when "xy", "XY" "%g,%g" % point.point when "index", "idx" point.index else # The \ are not strictly speaking necessary, but they make # ruby-mode happier raise "\'#{what}\' unkown: which coordinate(s) of the point do you want ?" end end
- Stats =
[]
Class Method Summary collapse
Class Method Details
.make_alias_for_option(cmd_name, option, new_name, deprecated = false) ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/ctioga2/commands/interpreter.rb', line 281 def self.make_alias_for_option(cmd_name, option, new_name, deprecated = false) cmd = Interpreter.command(cmd_name) if ! cmd raise "Impossible to find command #{cmd_name}" end new_opt = cmd.optional_arguments[option] if ! new_opt raise "No #{option} option to command #{cmd_name}" end new_opt = new_opt.dup new_opt.option_deprecated = deprecated new_opt.option_target = option cmd.optional_arguments[new_name] = new_opt end |