~ubuntu-branches/ubuntu/oneiric/ctioga2/oneiric

« back to all changes in this revision

Viewing changes to lib/ctioga2/commands/general-commands.rb

  • Committer: Bazaar Package Importer
  • Author(s): Vincent Fourmond
  • Date: 2011-01-24 21:36:06 UTC
  • Revision ID: james.westby@ubuntu.com-20110124213606-9ettx0ugl83z0bzp
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# general-commands.rb: various global scope commands
 
2
# copyright (c) 2009 by Vincent Fourmond
 
3
  
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
  
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details (in the COPYING file).
 
13
 
 
14
require 'ctioga2/utils'
 
15
require 'ctioga2/commands/general-types'
 
16
require 'ctioga2/commands/parsers/file'
 
17
 
 
18
module CTioga2
 
19
 
 
20
  Version::register_svn_info('$Revision: 155 $', '$Date: 2010-06-21 21:41:32 +0200 (Mon, 21 Jun 2010) $')
 
21
 
 
22
  module Commands
 
23
 
 
24
    # General scope commands.
 
25
    GeneralGroup = 
 
26
      CmdGroup.new('general', "General commands", 
 
27
                   "General scope commands", 1000)
 
28
    
 
29
 
 
30
    CommandLineHelpOptions = {
 
31
      'pager' => CmdArg.new('boolean')
 
32
    }
 
33
    
 
34
    # Display help on the command-line
 
35
    CommandLineHelpCommand = 
 
36
      Cmd.new("command-line-help", 'h', 
 
37
              "--help", [ ], CommandLineHelpOptions) do |plotmaker, options|
 
38
      plotmaker.interpreter.doc.display_command_line_help(options)
 
39
      exit 
 
40
    end
 
41
    
 
42
    CommandLineHelpCommand.describe("Prints help on command-line options and exits",
 
43
                                    <<EOH, GeneralGroup)
 
44
Prints helps about short and long options available when run from the
 
45
command-line.
 
46
EOH
 
47
    
 
48
    # Prints the version of ctioga2 used
 
49
    PrintVersion = Cmd.new("version", '-V', "--version", []) do |plotmaker|
 
50
      puts "This is ctioga2 version #{CTioga2::Version::version}"
 
51
    end
 
52
    
 
53
    PrintVersion.describe("Prints the version", 
 
54
                          "Prints the version of ctioga in use", 
 
55
                          GeneralGroup)
 
56
 
 
57
    # Includes a file
 
58
    RunCommandFile = 
 
59
      Cmd.new("include", '-f', "--file", 
 
60
              [ CmdArg.new('file'), ]) do |plotmaker, file|
 
61
      plotmaker.interpreter.run_command_file(file)
 
62
    end
 
63
    
 
64
    RunCommandFile.describe("Runs given command file", <<EOH, GeneralGroup)
 
65
Reads the file and runs commands found in them, using the ctioga language.
 
66
> ctioga2 -f my_file.ct2
 
67
EOH
 
68
 
 
69
    # Evaluate a series of commands.
 
70
    EvalCommand =  Cmd.new("eval", '-e', "--eval", 
 
71
                           [ CmdArg.new('commands'), ]) do |plotmaker, string|
 
72
      plotmaker.interpreter.run_commands(string)
 
73
    end
 
74
    
 
75
    EvalCommand.describe("Runs the given commands", <<EOH, GeneralGroup)
 
76
Runs the given strings as commands, as if given from a command file.
 
77
EOH
 
78
 
 
79
    # Increases verbosity
 
80
    VerboseLogging = 
 
81
      Cmd.new("verbose", '-v',  "--verbose", [ ]) do |plotmaker|
 
82
      CTioga2::Log::set_level(Logger::INFO)
 
83
    end
 
84
    
 
85
    VerboseLogging.describe("Makes ctioga2 more verbose", <<EOH, GeneralGroup)
 
86
With this on, ctioga2 outputs quite a fair amount of informative messages.
 
87
EOH
 
88
 
 
89
    # Write debugging information.
 
90
    #
 
91
    # \todo this should be the place where a lot of customization of
 
92
    # the debug output could go - including channels or things like
 
93
    # that. To be seen later on...
 
94
    DebugLogging = 
 
95
      Cmd.new("debug", nil,  "--debug", [ ]) do |plotmaker|
 
96
      CTioga2::Log::set_level(Logger::DEBUG)
 
97
    end
 
98
    
 
99
    DebugLogging.describe("Makes ctioga2 write out debugging information", 
 
100
                          <<EOH, GeneralGroup)
 
101
With this on, ctioga2 writes a whole lot of debugging information. You
 
102
probably will not need that unless you intend to file a bug report or
 
103
to tackle a problem yourself.
 
104
EOH
 
105
 
 
106
    # Includes a file
 
107
    EchoCmd = 
 
108
      Cmd.new("echo", nil,  "--echo", [ ]) do |plotmaker|
 
109
      STDERR.puts "Command-line used: "
 
110
      STDERR.puts plotmaker.quoted_command_line
 
111
    end
 
112
    
 
113
    EchoCmd.describe("Prints command-line used to standard error", 
 
114
                     <<EOH, GeneralGroup)
 
115
Writes the whole command-line used to standard error, quoted in such a
 
116
way that it should be usable directly for copy/paste.
 
117
EOH
 
118
    
 
119
    
 
120
  end
 
121
end
 
122