class Mixml::Application
Mixml
application class
Public Instance Methods
modify_command(name) { |c| ... }
click to toggle source
Create a new modification command
@param name [Symbol] command name
# File lib/mixml/application.rb, line 125 def modify_command(name) c = add_command ModifyCommand.new(name) yield c if block_given? end
run()
click to toggle source
Run the mixml command
# 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, options| $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, options| script = options.expression || File.read(options.script) $tool.work(args) do execute(script) end end end run! end
select_command(name) { |c| ... }
click to toggle source
Create a new selection command
@param name [Symbol] command name
# File lib/mixml/application.rb, line 117 def select_command(name) c = add_command SelectCommand.new(name) yield c if block_given? end