Class: Mixml::Application
- Inherits:
-
Object
- Object
- Mixml::Application
- Includes:
- Commander::Methods
- Defined in:
- lib/mixml/application.rb
Overview
Mixml application class
Defined Under Namespace
Classes: ModifyCommand, SelectCommand
Instance Method Summary collapse
-
#modify_command(name) {|c| ... } ⇒ Object
Create a new modification command.
-
#run ⇒ Object
Run the mixml command.
-
#select_command(name) {|c| ... } ⇒ Object
Create a new selection command.
Instance Method Details
#modify_command(name) {|c| ... } ⇒ Object
Create a new modification command
125 126 127 128 |
# File 'lib/mixml/application.rb', line 125 def modify_command(name) c = add_command ModifyCommand.new(name) yield c if block_given? end |
#run ⇒ Object
Run the mixml command
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/mixml/application.rb', line 131 def run program :name, 'mixml' program :version, Mixml::VERSION program :description, 'XML helper tool' $tool = Mixml::Tool.new global_option('-p', '--pretty', 'Pretty print output') do |value| $tool.pretty = value end global_option('-i', '--inplace', 'Replace the processed files with the new files') do |value| $tool.save = value $tool.print = !value end global_option('-q', '--quiet', 'Do not print nodes') do |value| $tool.print = !value end command :pretty do |c| c.description = 'Pretty print XML files' c.action do |args, | $tool.pretty = true $tool.work(args) end end modify_command :write do |c| c.description = 'Write selected nodes to the console' c.suppress_output = true c.optional_expression = true end select_command :remove do |c| c.description = 'Remove nodes from the XML documents' end modify_command :replace do |c| c.description = 'Replace nodes in the XML documents' end modify_command :append do |c| c.description = 'Append child nodes in the XML documents' end modify_command :rename do |c| c.description = 'Rename nodes in the XML documents' end modify_command :value do |c| c.description = 'Set node values' end command :execute do |c| c.description = 'Execute script on the XML documents' c.option '-s', '--script STRING', String, 'Script file to execute' c.option '-e', '--expression STRING', String, 'Command to execute' c.action do |args, | script = .expression || File.read(.script) $tool.work(args) do execute(script) end end end run! end |
#select_command(name) {|c| ... } ⇒ Object
Create a new selection command
117 118 119 120 |
# File 'lib/mixml/application.rb', line 117 def select_command(name) c = add_command SelectCommand.new(name) yield c if block_given? end |