Class: Appleseed::Generator::Options

Inherits:
Hash
  • Object
show all
Defined in:
lib/appleseed/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



6
7
8
9
10
11
12
13
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/appleseed/options.rb', line 6

def initialize(args)
  super()

  @orig_args = args.clone

  git_config =  if Pathname.new("~/.gitconfig").expand_path.exist?
                  Git.global_config
                else
                  {}
                end
  self[:user_name]       = ENV['GIT_AUTHOR_NAME']  || ENV['GIT_COMMITTER_NAME']  || git_config['user.name']
  self[:user_email]      = ENV['GIT_AUTHOR_EMAIL'] || ENV['GIT_COMMITTER_EMAIL'] || git_config['user.email']
  self[:github_username] = git_config['github.user']
  self[:github_token]    = git_config['github.token']

  require 'optparse'
  @opts = OptionParser.new do |o|
    o.banner = "Usage: #{File.basename($0)} [options] web-app-name\ne.g. #{File.basename($0)} new-years-2011"

    o.separator ""

    o.on('--description [DESCRIPTION]', 'specify a description of the project') do |description|
      self[:description] = description
    end

    o.separator ""

    o.on('--github-username [GITHUB_USERNAME]', "name of the user on GitHub to set the project up under") do |github_username|
      self[:github_username] = github_username
    end

    o.on('--github-token [GITHUB_TOKEN]', "GitHub token to use for interacting with the GitHub API") do |github_token|
      self[:github_token] = github_token
    end

    o.on('--git-remote [GIT_REMOTE]', 'URI to set the git origin remote to') do |git_remote|
      self[:git_remote] = git_remote
    end

    o.on('--no-github', 'don\'t create the repository on GitHub') do
      self[:no_github] = true
    end

    o.on('--no-heroku', 'don\'t create a deployment on Heroku') do
      self[:no_heroku] = true
    end

    o.separator ""
    
    o.on('--template [template_url]', "the URL or path for a custom Rails template file") do |template_url|
      self[:template_url] = template_url
    end
    
    o.separator ""

    o.on_tail('-h', '--help', 'display this help and exit') do
      self[:show_help] = true
    end
  end

  begin
    @opts.parse!(args)
    self[:project_name] = args.shift
  rescue OptionParser::InvalidOption => e
    self[:invalid_argument] = e.message
  end
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



4
5
6
# File 'lib/appleseed/options.rb', line 4

def opts
  @opts
end

#orig_argsObject (readonly)

Returns the value of attribute orig_args.



4
5
6
# File 'lib/appleseed/options.rb', line 4

def orig_args
  @orig_args
end

Instance Method Details

#merge(other) ⇒ Object



74
75
76
# File 'lib/appleseed/options.rb', line 74

def merge(other)
  self.class.new(@orig_args + other.orig_args)
end