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.



15
16
17
18
19
20
21
# File 'lib/dev.rb', line 15

def initialize env=nil
	@env=Environment.new(env) if !env.nil? && env.kind_of?(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.



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

def commands
  @commands
end

#envObject

Returns the value of attribute env.



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

def env
  @env
end

#projectsObject

Returns the value of attribute projects.



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

def projects
  @projects
end

Instance Method Details

#execute(args) ⇒ Object



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

def execute args
	args=args.split(' ') if(args.kind_of?(String))

       # parse arguments that are of the form KEY=VALUE
	args.each{|arg|
	 	if(arg.include?('='))
	 		words=arg.split('=')
	 		if(words.length==2)
	 			ENV[words[0]]=words[1]
	 		end
	 	end
	}

	if args.length == 0
       return usage
    else
	   subcommand=args[0] if args.length > 0
	   subargs=Array.new
	   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