Class: Dev

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ Dev

Returns a new instance of Dev.



17
18
19
20
21
22
23
# File 'lib/dev.rb', line 17

def initialize(env = nil)
  @env = Environment.new(env) if !env.nil? && env.is_a?(Hash)
  @env = Environment.new if @env.nil?
  @projects = Projects.new(@env)
  @commands = Commands.new(@env)
  @output = ""
end

Instance Attribute Details

#commandsObject

Returns the value of attribute commands.



15
16
17
# File 'lib/dev.rb', line 15

def commands
  @commands
end

#envObject

Returns the value of attribute env.



15
16
17
# File 'lib/dev.rb', line 15

def env
  @env
end

#projectsObject

Returns the value of attribute projects.



15
16
17
# File 'lib/dev.rb', line 15

def projects
  @projects
end

Instance Method Details

#execute(args) ⇒ Object



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
# File 'lib/dev.rb', line 25

def execute(args)
  args = args.split(" ") if args.is_a?(String)

  # parse arguments that are of the form KEY=VALUE
  args.each do |arg|
    next unless arg.include?("=")

    words = arg.split("=")
    ENV[words[0]] = words[1] if words.length == 2
  end

  if args.length.zero?
    usage
  else
    subcommand = args[0] if args.length.positive?
    subargs = []
    subargs = args[1, args.length - 1] if args.length > 1

    return projects.add(subargs) if subcommand == "add"
    return projects.clobber(subargs) if subcommand == "clobber"
    return projects.import(subargs) if subcommand == "import"
    return projects.list(subargs) if subcommand == "list"
    return projects.make(subargs) if subcommand == "make"
    return projects.info(subargs) if subcommand == "info"
    return projects.remove(subargs) if subcommand == "remove"
    return projects.work(subargs) if subcommand == "work"
    return projects.update(subargs) if subcommand == "update"

    @env.out "unknown command: '#{subcommand}'"
    1
  end
end

#usageObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dev.rb', line 58

def usage
  return 0
  @env.out "usage: dev <subcommand> [options]"
  @env.out ""
  @env.out "available subcommands"
  @env.out " help"
  @env.out " list"
  @env.out " make"
  @env.out " info"
  @env.out " work"
  @env.out ""
  @env.out "Type 'dev help <subcommand>' for help on a specific subcommand.'"
  0
end