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/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, 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, "A file name.\n")
TextType =

Plain text

CmdType.new('text', :string, "Plain text.\n")
DatasetType =

A series of datasets

CmdType.new('dataset', :string, "One expandable dataset.\n")
CommandsType =

Commands

CmdType.new('commands', :string, "ctioga2 commands, such as the ones that could be found in\ncommand files.\n")
BooleanType =
CmdType.new('boolean', :boolean, "Yes or no.\n")
FloatType =
CmdType.new('float', :float, "A floating-point number.\n")
FloatOrFalseType =
CmdType.new('float-or-false', {
                              :type => :float,
                              :shortcuts => {'none' => false }}, 
                              "A floating-point number, or @none@.\n")
FloatList =
CmdType.new('float-list', 
                            {
                              :type => :array,
                              :subtype => :float,
                              :separator => /\s+|\s*,\s*/,
                              :separator_out => " "
                            }, "A list of space-separated or comma-separated floating point numbers.\n")
TextList =
CmdType.new('text-list', 
                            {
                              :type => :array,
                              :subtype => :string,
                              :separator => /\s*,\s*/,
                              :alternative_separator => /\s*\|\|\s*/,
                              :separator_out => ","
                            }, "A list of comma-separated texts. If you must include a comma inside the\ntexts, then use @||@ as a separator.\n")
IntegerType =
CmdType.new('integer', :integer, "An integer.\n")
IntegerList =
CmdType.new('integer-list', 
                            {
                              :type => :array,
                              :subtype => :integer,
                              :separator => /\s+|\s*,\s*/,
                              :separator_out => " "
                            }, "A list of space-separated or comma-separated integers\n")
PartialFloatRangeType =
CmdType.new('partial-float-range', 
                                        :partial_float_range, "A beginning:end range, where either of the endpoints can be ommitted.\n")
FloatRangeType =
CmdType.new('float-range', 
                                 :float_range, "A beginning:end range.\n")
StringOrRegexp =
CmdType.new('regexp', 
                                 :string_or_regexp, "A plain string or a regular expression (the latter being enclosed \nwithin /.../).\n")
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, "A point from an already-loaded Dataset. You have two ways to choose the point:\n\n * @@13@ takes the 13th point in the last dataset;\n * @0.2@ takes the point the closest to 20% of the dataset.\n\nIf you need another dataset than the last one, give its number or\nnamed within brackets: @{-2}0.2@ is the point closest to the 20% of\nthe one-before-last dataset.\n")
LaTeXFontType =

A LaTeX font

CmdType.new('latex-font', :latex_font, "A LaTeX font.\n\n@todo document !\n")
ColorMapType =

A color map

CmdType.new('colormap', :colormap, "A Z color map. It takes the form @Color1--Color2--Color3...@. All\ncolors can optionally be followed by a number. For instance, for\n@Red--Blue--Pink--Green@, the colors are evenly spaced. In the case\n@Red--Blue(0.1)--Pink(0.2)--Green@, the Blue to Pink strech is located\nbetween Z values 0.1 and 0.2.\n\nIf a prefix @hls:@ or @wheel:@ is present, then linear interpolation\nis done in the HLS colorspace instead of the RGB one (the default).\n\nIf a suffix @:sym:@_value_ is present, then the colormap is symmetric\naround that value.\n\nIt is also possible to directly use a {type: color-set}, in which case\neveything works as if the colors of the {type: color-set} had been\ngiven directly, without Z values.\n")
StoredDatasetType =

A stored dataset.

CmdType.new('stored-dataset', 
                                    :string, "A dataset that has already been loaded. It is either:\n * A number, in which case it specifies the index inside the stack. 0\n   is the first on that was pushed onto the stack (the oldest\n   dataset), 1 the second, -1 the last one, -2 the one before the last\n   and so on. (it works just like Ruby's arrays).\n * The name of a named dataset.\n")
AxisType =

Something meant to be fed to PlotStyle#get_axis_style

CmdType.new('axis', :string, "The name of the axis of a plot. It can be:\n * @left@, @top@, @bottom@ or @right@;\n * @x@, @xaxis@, @y@, @yaxis@, which return one of the above depending \n   on the preferences of the current plot (see {command: xaxis} and \n   {command: yaxis} to change them);\n * one of the named axes, such as the ones created by \n   {command: new-zaxis}.\n")
LabelType =

Something meant to be fed to PlotStyle#get_label_style

CmdType.new('label', :string, "The name of an label. It can be:\n * @title@ to mean the current plot's title.\n * @axis_tick@ or @axis_ticks@ or simply @axis@, where @axis@ is a a valid\n   {type: axis}. It designates the ticks of the named axis.\n * @axis_label@, same as above but targets the label of the named axis.\n")
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, options|
  plotmaker.interpreter.doc.display_command_line_help(options)
  exit 
end
HelpOnCommand =

Display help on the command-line

Cmd.new("help-on", nil, 
          "--help-on", [CmdArg.new('text') ]) do |plotmaker, cmd, options|
  plotmaker.interpreter.doc.display_help_on(cmd, options)
  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 =

Includes a file

Cmd.new("echo", nil,  "--echo", [ ]) do |plotmaker|
  STDERR.puts "Command-line used: "
  STDERR.puts plotmaker.quoted_command_line
end
FuncEval =
Function.new("eval", "Evaluate Ruby code") do |pm, code|
  Ruby::run_code(code)
end
FuncPoint =
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

Class Method Summary collapse

Class Method Details

.make_alias_for_option(cmd_name, option, new_name, deprecated = false) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/ctioga2/commands/interpreter.rb', line 271

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