Class: Branston

Inherits:
Object
  • Object
show all
Defined in:
lib/branston/lib/branston.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Branston

Returns a new instance of Branston.



12
13
14
15
# File 'lib/branston/lib/branston.rb', line 12

def initialize(args)
  self.args = args
  go()
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



10
11
12
# File 'lib/branston/lib/branston.rb', line 10

def args
  @args
end

Instance Method Details

#goObject



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
73
74
75
76
77
78
79
# File 'lib/branston/lib/branston.rb', line 17

def go

  options = {
    :Port        => PORT,
    :Host        => "0.0.0.0",
    :environment => (ENV['RAILS_ENV'] || "production").dup,
    :detach      => true,
    :debugger    => false,
    :path        => nil,
    :directory   => BRANSTON_HOME
  }

  actions = []

  ARGV.clone.options do |opts|
    opts.on("-i", "--init", String, "Initialise Branston") {
      opts.on("-w", "--working=directory", String, "Initialise branston in the given " +
        "directory", "Default: .branston") { |v| options[:directory] =v }
      actions << 'init'
    }
    opts.on("-s", "--server", String, "Run a Branston Server") {
      opts.on("-p", "--port=port", Integer,
        "Runs Branston on the specified port.", "Default: #{PORT}") { |v| options[:Port] = v }
      opts.on("-b", "--binding=ip", String,
        "Binds Branston to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v }
      opts.on("-P", "--path=/path", String, "Runs Branston mounted at a " +
        "specific path.", "Default: /") { |v| options[:path] = v }
      opts.on("-w", "--working=directory", String, "Run branston in the given " +
        "directory, the same directory that you branston --initialised into",
      "Default: .branston") { |v| options[:directory] =v }
      opts.on("-fg", "--foreground", String) { |v| options[:foreground] = true }
      actions << 'server'
    }
    opts.on("-g", "--generate", String, "Generate a feature from a Branston Server") {
       opts.on("-p", "--port=port", Integer,
        "Access a branston server on the specified port.", "Default: #{PORT}") { |v| options[:Port] = v }
      opts.on("-b", "--binding=ip", String,
        "Access a branston server on the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v }
      opts.on("-f", "--feature=name", String,
        "Generate a feature for the given story regular expression.") { |v| options[:feature] = v }
      actions << 'generator'
    }
    opts.separator ""
    opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
    opts.parse!

    if ARGV.empty? or actions.size != 1
      puts opts; exit
    end
  end

  if actions.first == 'server'
    launch_branston_server(options)
  elsif actions.first == 'generator'
    client = Client.new(options)
    client.generate_story_files
    client.errors.each do |error|
      puts error
    end
  elsif actions.first == 'init'
    initialise_branston(options)
  end
end