Class: Madman::Commands::Nav
- Inherits:
-
MisterBin::Command
- Object
- MisterBin::Command
- Madman::Commands::Nav
- Includes:
- Colsole
- Defined in:
- lib/madman/commands/nav.rb
Instance Method Summary collapse
- #depth ⇒ Object
-
#dir ⇒ Object
CLI Arguments.
- #dry? ⇒ Boolean
- #force? ⇒ Boolean
- #marker ⇒ Object
- #recursive? ⇒ Boolean
- #run ⇒ Object
- #target ⇒ Object
- #update_file(file) ⇒ Object
- #verbose? ⇒ Boolean
Instance Method Details
#depth ⇒ Object
57 |
# File 'lib/madman/commands/nav.rb', line 57 def depth; args['--depth'].to_i; end |
#dir ⇒ Object
CLI Arguments
56 |
# File 'lib/madman/commands/nav.rb', line 56 def dir; args['DIR'] || '.'; end |
#dry? ⇒ Boolean
61 |
# File 'lib/madman/commands/nav.rb', line 61 def dry?; args['--dry']; end |
#force? ⇒ Boolean
60 |
# File 'lib/madman/commands/nav.rb', line 60 def force?; args['--force']; end |
#marker ⇒ Object
58 |
# File 'lib/madman/commands/nav.rb', line 58 def marker; args['--marker']; end |
#recursive? ⇒ Boolean
63 |
# File 'lib/madman/commands/nav.rb', line 63 def recursive?; args['--recursive']; end |
#run ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/madman/commands/nav.rb', line 29 def run if recursive? Dir["#{dir}/**/#{target}"].each { |file| update_file file } else update_file "#{dir}/#{target}" end say dry? ? "Done (dry mode, no changes were made)" : "Done" end |
#target ⇒ Object
59 |
# File 'lib/madman/commands/nav.rb', line 59 def target; args['--target']; end |
#update_file(file) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/madman/commands/nav.rb', line 39 def update_file(file) say "Updating !txtgrn!#{file}" file_dir = File.dirname file toc = Madman::Navigation.new file_dir, depth: depth doc = Madman::Document.from_file file doc.inject toc.markdown, marker: marker, force: force? if verbose? say word_wrap " !txtblu!#{doc.text}" say "" end doc.save unless dry? end |
#verbose? ⇒ Boolean
62 |
# File 'lib/madman/commands/nav.rb', line 62 def verbose?; args['--verbose']; end |