Class: OrgMode::Commands::Update

Inherits:
Object
  • Object
show all
Defined in:
lib/org_mode/commands/update.rb

Instance Method Summary collapse

Instance Method Details

#execute(args, options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/org_mode/commands/update.rb', line 10

def execute(args, options)
  # use supplied file-name 
  # or use files out of configuration
  args = OrgMode::Configuration.org_mode_files if args.blank?

  args.each do |file_path|
    OrgMode::FileTools.backup(file_path)

    org_file = OrgMode::Loader.load_and_parse_file(file_path)

    if options.archive_done
      org_file = OrgMode::Processors::ArchiveDone.new(org_file).process
    end

    org_formatter = OrgMode::Formatters::Textual.new(org_file)

    OrgMode::FileTools.spit_into_file(org_formatter.format, file_path)
  end

rescue StandardError => e
  puts "Encountered a little problem: #{e}"
end