# general-commands.rb: various global scope commands # copyright (c) 2009 by Vincent Fourmond # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details (in the COPYING file). require 'ctioga2/utils' require 'ctioga2/commands/general-types' require 'ctioga2/commands/parsers/file' module CTioga2 module Commands # General scope commands. GeneralGroup = CmdGroup.new('general', "General commands", "General scope commands", 1000) CommandLineHelpOptions = { 'pager' => CmdArg.new('boolean') } # Display help on the command-line CommandLineHelpCommand = Cmd.new("command-line-help", 'h', "--help", [ ], CommandLineHelpOptions) do |plotmaker, options| plotmaker.interpreter.doc.display_command_line_help(options) exit end CommandLineHelpCommand.describe("Prints help on command-line options and exits", < 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 RunCommandFile.describe("Runs given command file", < ctioga2 -f my_file.ct2 If the @/log@ is on, then all messages are written to a -log.txt file instead of to the terminal. EOH # Evaluate a series of commands. EvalCommand = Cmd.new("eval", '-e', "--eval", [ CmdArg.new('commands'), ]) do |plotmaker, string| plotmaker.interpreter.run_commands(string) end EvalCommand.describe("Runs the given commands", <