Module: Mint::CommandLine
- Defined in:
- lib/mint/commandline.rb
Class Method Summary collapse
-
.config ⇒ Object
Display all active configurations, where local configurations override global ones.
- .configuration(file = ) ⇒ Object
- .configuration_with(opts) ⇒ Object
- .configure(opts, scope = :local) ⇒ Object
-
.edit(name, commandline_options) ⇒ Object
If we get the edit command, will retrieve appropriate file (probably a Mint template) and shell out that file to the user’s favorite editor.
- .help(message) ⇒ Object
-
.install(file, commandline_options) ⇒ Object
Install the listed file to the scope listed, using local as the default scope.
-
.mint(files, commandline_options) ⇒ Object
Renders and writes to file all resources described by a document.
-
.options ⇒ Object
A map of all options that mint allows by default.
- .parser(options_metadata = Mint::CommandLine.options) ⇒ Object
-
.set(key, value, commandline_options) ⇒ Object
Try to set a config option (at the specified scope) per the user’s command.
Class Method Details
.config ⇒ Object
Display all active configurations, where local configurations override global ones.
117 118 119 |
# File 'lib/mint/commandline.rb', line 117 def self.config puts YAML.dump(configuration) end |
.configuration(file = ) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mint/commandline.rb', line 40 def self.configuration(file=Mint.files[:config]) return nil unless file config_file = Pathname.new file # Merge config options from all config files on the Mint path, # where more local options take precedence over more global # options configuration = Mint.path(true).map {|p| p + config_file }. select(&:exist?). map {|p| YAML.load_file p }. reverse. reduce(Mint.) {|r,p| r.merge p } Helpers.symbolize_keys configuration end |
.configuration_with(opts) ⇒ Object
56 57 58 |
# File 'lib/mint/commandline.rb', line 56 def self.configuration_with(opts) configuration.merge opts end |
.configure(opts, scope = :local) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/mint/commandline.rb', line 97 def self.configure(opts, scope=:local) config_directory = Mint.path_for_scope(scope, true) config_file = config_directory + Mint.files[:config] Helpers.ensure_directory config_directory Helpers.update_yaml opts, config_file end |
.edit(name, commandline_options) ⇒ Object
If we get the edit command, will retrieve appropriate file (probably a Mint template) and shell out that file to the user’s favorite editor.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mint/commandline.rb', line 79 def self.edit(name, ) layout = [:layout] style = [:style] if layout and not style layout_or_style = :layout elsif style layout_or_style = :style else puts optparse.help end file = Mint.lookup_template name, layout_or_style editor = ENV['EDITOR'] || 'vi' system "#{editor} #{file}" end |
.help(message) ⇒ Object
60 61 62 |
# File 'lib/mint/commandline.rb', line 60 def self.help() puts end |
.install(file, commandline_options) ⇒ Object
Install the listed file to the scope listed, using local as the default scope.
66 67 68 69 70 71 72 73 74 |
# File 'lib/mint/commandline.rb', line 66 def self.install(file, ) [:local] = true scope = [:global, :user, :local]. select {|e| [e] }. first directory = path_for_scope(scope) FileUtils.copy file, directory end |
.mint(files, commandline_options) ⇒ Object
Renders and writes to file all resources described by a document. Specifically: it renders itself (inside of its own layout) and then renders its style. This method will overwrite any existing content in a document’s destination files. The ‘render_style` option provides an easy way to stop Mint from rendering a style, even if the document’s style is not nil.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/mint/commandline.rb', line 127 def self.mint(files, ) documents = [] = configuration_with [:root] ||= Dir.getwd # Eventually render_style should be replaced with file # change detection render_style = true files.each do |file| Document.new(file, ).publish!(render_style) render_style = false end end |
.options ⇒ Object
A map of all options that mint allows by default. Mint will consume these arguments, with optional parameters, from the commandline. (All other arguments are taken to be filenames.)
11 12 13 14 |
# File 'lib/mint/commandline.rb', line 11 def self. = "../../../#{Mint.files[:syntax]}" YAML.load_file File.(, __FILE__) end |
.parser(options_metadata = Mint::CommandLine.options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mint/commandline.rb', line 16 def self.parser(=Mint::CommandLine.) optparse = OptionParser.new do |opts| opts. = 'Usage: mint [command] files [options]' Helpers.symbolize_keys().each do |k,v| has_param = v[:parameter] v[:short] = "-#{v[:short]}" v[:long] = "--#{v[:long]}" if has_param v[:long] << " PARAM" opts.on v[:short], v[:long], v[:description] do |p| yield k.to_sym, p end else opts.on v[:short], v[:long], v[:description] do yield k, true end end end end end |
.set(key, value, commandline_options) ⇒ Object
Try to set a config option (at the specified scope) per the user’s command.
106 107 108 109 110 111 112 113 |
# File 'lib/mint/commandline.rb', line 106 def self.set(key, value, ) [:local] = true scope = [:global, :user, :local]. select {|e| [e] }. first configure({ key => value }, scope) end |