Module: NanDoc::Cli::CommandMethods

Included in:
Cri::Base, NanDoc::Commands::Diff, NanDoc::CreateNanDocSite, DataSource
Defined in:
lib/nandoc/cli/command-methods.rb

Instance Method Summary collapse

Instance Method Details

#command_abort(msg = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nandoc/cli/command-methods.rb', line 23

def command_abort msg=nil
  if msg.nil?
    tail = 'Aborting.'
  elsif msg.index("for more info") # not mr. right, mr. right now
    tail = ''
  else
    last = msg[-1].chr
    tail = ".?!".index(last) ? '  ' : ("\n"==last ? '' : '.  ')
    tail << 'Aborting.'
  end
  $stderr.puts "nanDoc: #{msg}#{tail}"
  exit 1
end

#command_nameObject



6
7
8
9
# File 'lib/nandoc/cli/command-methods.rb', line 6

def command_name
  (/::([_a-z0-9]+)\Z/i =~ self.class.to_s and base = $1) or fail('no')
  base.gsub(/([a-z])([A-Z])/){ "#{$1}-#{$2}" }.downcase
end

#command_path_assert(name, *paths) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/nandoc/cli/command-methods.rb', line 13

def command_path_assert name, *paths
  paths.each do |p|
    unless File.exist?(p)
      command_abort("#{name} does not exist: #{p}")
    end
  end
end

#invite_to_more_command_helpObject



10
11
12
# File 'lib/nandoc/cli/command-methods.rb', line 10

def invite_to_more_command_help
  "see `nandoc help #{command_name}` for more information."
end

#invocation_nameObject



20
21
22
# File 'lib/nandoc/cli/command-methods.rb', line 20

def invocation_name
  File.basename($PROGRAM_NAME)
end