Class: Jiveapps::Command::Base
- Inherits:
-
Object
- Object
- Jiveapps::Command::Base
show all
- Includes:
- Helpers
- Defined in:
- lib/jiveapps/commands/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
#ask, #catch_args, #check_git_version, #confirm, #confirm_command, #debug, #debug_mode?, #display, #display_oauth_services, #error, #get_app_prop_with_default, #get_or_set_git_prop, #git_version, #has_program?, #home_directory, #run, #running_on_a_mac?, #running_on_windows?, #sh, #usage, #user_git_version
Constructor Details
#initialize(args, jiveapps = nil) ⇒ Base
Returns a new instance of Base.
7
8
9
10
11
|
# File 'lib/jiveapps/commands/base.rb', line 7
def initialize(args, jiveapps=nil)
@args = args
@jiveapps = jiveapps
@autodetected_app = false
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
5
6
7
|
# File 'lib/jiveapps/commands/base.rb', line 5
def args
@args
end
|
#autodetected_app ⇒ Object
Returns the value of attribute autodetected_app.
6
7
8
|
# File 'lib/jiveapps/commands/base.rb', line 6
def autodetected_app
@autodetected_app
end
|
Instance Method Details
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/jiveapps/commands/base.rb', line 17
def (force=true)
app = ('--app', false)
raise(CommandFailed, "You must specify an app name after --app") if app == false
unless app
app = (Dir.pwd) ||
raise(CommandFailed, "No app specified.\nRun this command from app folder or set it adding --app <app name>") if force
@autodetected_app = true
end
app
end
|
47
48
49
50
|
# File 'lib/jiveapps/commands/base.rb', line 47
def
remote = %x{ git config jiveapps.remote }.strip
remote == "" ? nil : remote
end
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/jiveapps/commands/base.rb', line 28
def (dir)
return unless remotes = git_remotes(dir)
if remote = ('--remote')
remotes[remote]
elsif remote =
remotes[remote]
else
apps = remotes.values.uniq
case apps.size
when 0; return nil
when 1; return apps.first
else
current_dir_name = dir.split('/').last.downcase
apps.select { |a| a.downcase == current_dir_name }.first
end
end
end
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/jiveapps/commands/base.rb', line 72
def (options, default=true)
values = options.is_a?(Array) ? options : [options]
return unless opt_index = args.select { |a| values.include? a }.first
opt_position = args.index(opt_index) + 1
if args.size > opt_position && opt_value = args[opt_position]
if opt_value.include?('--')
opt_value = nil
else
args.delete_at(opt_position)
end
end
opt_value ||= default
args.delete(opt_index)
block_given? ? yield(opt_value) : opt_value
end
|
#git_remotes(base_dir) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/jiveapps/commands/base.rb', line 52
def git_remotes(base_dir)
git_config = "#{base_dir}/.git/config"
unless File.exists?(git_config)
parent = base_dir.split('/')[0..-2].join('/')
return git_remotes(parent) unless parent.empty?
else
remotes = {}
current_remote = nil
File.read(git_config).split(/\n/).each do |l|
current_remote = $1 if l.match(/\[remote \"([\w\d-]+)\"\]/)
app = (l.match(/url = git@#{jiveapps.git_host}:([\w\d-]+)\.git/) || [])[1]
if current_remote && app
remotes[current_remote.downcase] = app
current_remote = nil
end
end
return remotes
end
end
|
#jiveapps ⇒ Object
13
14
15
|
# File 'lib/jiveapps/commands/base.rb', line 13
def jiveapps
@jiveapps ||= Jiveapps::Command.run_internal('auth:client', args)
end
|