Class: Mdexport

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
lib/mdexport.rb

Instance Method Summary collapse

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mdexport.rb', line 14

def run
  program :name, 'mdexport'
  program :version, '0.0.5'
  program :description, 'mdexport is a command line that exports markdown files into html files.'
  
  default_command :run

  command :run do |c|
    c.syntax = 'mdexport [--path /path/to/folder] [--watch] [--clean] [--output /path/to/output_file]'
    c.description = 'Exports the markdown files from folder to html files.'
    c.option '--path STRING', String, 'Path to folder that contains the markdown files.'
    c.option '--output STRING', String, 'Path to output file.'
    c.option '--watch', 'Watch markdown file changes.'
    c.option '--clean', 'Clean html files on folder.'
    c.option '--merge', 'Merge markdown files in a given output file.'
    
    c.action do |args, opt|
      opt.default :path => '.'
      opt.default :output => nil
      opt.default :watch => false
      opt.default :clean => false
      opt.default :merge => false
      
      opt.path = File.expand_path opt.path
      opt.output = File.expand_path opt.output if opt.output

      check_path(opt.path)
      #check_path(opt.output) if opt.output
      
      error "Incompatible params: merge, output." if opt.merge == true && opt.output == nil
      error "Incompatible params: clean, watch." if opt.clean == true && opt.watch == true
      error "Incompatible params: output, watch." if opt.output != nil && opt.watch == true
      
      process opt.path, opt.clean, opt.watch, opt.output, opt.merge
    end
  end

  run!
end