Module: Hen::Commands

Extended by:
CLI, Commands
Included in:
Commands
Defined in:
lib/hen/commands.rb

Constant Summary collapse

COMMANDS =
{
  'config'  => 'Create a fresh .henrc file',
  'create'  => [
    'Create a new project directory tree',
    'Arguments: path [sample-skeleton]',
    'Options: -g, --git [[remote=]url]'
  ],
  'help'    => 'Print this help and exit',
 #'list'    => 'List available hens with their tasks',
  'version' => 'Display version number'
}
USAGE =
<<-EOT
Usage: #{$0} {#{COMMANDS.keys.sort.join('|')}} [arguments] [options]
   #{$0} [-h|--help] [--version]
EOT
SKELETON =
File.expand_path('../../../example', __FILE__)

Instance Method Summary collapse

Methods included from CLI

classname, emailaddress, fullname, githubuser, progdesc, progname, progsumm, render

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object (private)


122
123
124
# File 'lib/hen/commands.rb', line 122

def method_missing(method, *)
  abort "Illegal command: #{method}\n#{USAGE}"
end

Instance Method Details

#[](arg) ⇒ Object


61
62
63
64
# File 'lib/hen/commands.rb', line 61

def [](arg)
  arg = arg.sub(/\A-+/, '')
  arg !~ /\W/ && public_method_defined?(arg) ? send(arg) : method_missing(arg)
end

#configObject


96
97
98
99
100
101
# File 'lib/hen/commands.rb', line 96

def config
  render(File.join(SKELETON, '_henrc'), henrc = Hen.default_henrc)

  puts
  puts "Your .henrc has been created: #{henrc}. Now adjust it to your needs."
end

#createObject


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/hen/commands.rb', line 103

def create
  abort 'Path argument missing!' unless path = ARGV.shift

  skel = ARGV.first !~ /^-/ && ARGV.shift || File.join(SKELETON, 'project')
  abort "Project skeleton not found: #{skel}" unless File.directory?(skel)

  create_path(path = File.expand_path(path), created = [])
  create_skel(path, skel = File.expand_path(skel), created, replace = {})

  puts
  puts "Your new project directory has been created: #{path}. Have fun!"

  replace.each { |target, details|
    puts ["\n#{target}:", *details].join("\n  ") unless details.empty?
  }.clear
end

#helpObject Also known as: h


70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/hen/commands.rb', line 70

def help
  puts USAGE
  puts
  puts 'Commands:'

  max = COMMANDS.keys.map(&:length).max

  COMMANDS.sort.each { |cmd, desc|
    puts "  %-#{max}s - %s" % [cmd, (desc = [*desc]).shift]
    desc.each { |extra| puts "  %#{max}s   + %s" % [' ', extra] }
  }
end

#listObject


85
86
87
88
89
90
# File 'lib/hen/commands.rb', line 85

def list
  # How to achieve? Has to list *all* hens and tasks made available therein,
  # *regardless* of any missing prerequisites (preferably indicating whether
  # a particular hen/task is currently available).
  abort 'Sorry, not yet available...'
end

#usageObject


66
67
68
# File 'lib/hen/commands.rb', line 66

def usage
  abort USAGE
end

#versionObject


92
93
94
# File 'lib/hen/commands.rb', line 92

def version
  puts "hen v#{VERSION}"
end