fanforce-cli 1.7.1 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -65
- data/Rakefile +1 -1
- data/bin/fanforce +1 -17
- data/fanforce-cli.gemspec +10 -18
- data/lib/fanforce/cli.rb +5 -10
- data/lib/fanforce/cli/_load.rb +177 -0
- data/lib/fanforce/cli/app.rb +16 -26
- data/lib/fanforce/cli/apps.rb +10 -19
- data/lib/fanforce/cli/scripts/version.rb +12 -0
- data/lib/fanforce/cli/utils.rb +64 -44
- data/lib/fanforce/cli/version.rb +1 -1
- metadata +15 -119
- data/bin/fanforce-supercharge +0 -7
- data/lib/fanforce/cli/_base.rb +0 -263
- data/lib/fanforce/cli/commands.rb +0 -512
- data/lib/fanforce/cli/commands_support.rb +0 -205
- data/lib/fanforce/cli/env.rb +0 -41
- data/lib/fanforce/cli/files.rb +0 -290
- data/lib/fanforce/cli/help.rb +0 -99
- data/lib/fanforce/cli/run.rb +0 -53
@@ -0,0 +1,12 @@
|
|
1
|
+
class Fanforce::CLI::Scripts
|
2
|
+
include Fanforce::CLI::Utils
|
3
|
+
|
4
|
+
Fanforce::CLI.register self, :version, [nil, 'Display your current Fanforce CLI version number']
|
5
|
+
|
6
|
+
def version(*args)
|
7
|
+
puts divider '++----------------------------------------------------------------------------------------------------'
|
8
|
+
puts "You are using Fanforce::CLI v#{Fanforce::CLI::VERSION}"
|
9
|
+
puts divider '----------------------------------------------------------------------------------------------------++'
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
data/lib/fanforce/cli/utils.rb
CHANGED
@@ -1,70 +1,90 @@
|
|
1
1
|
module Fanforce::CLI::Utils
|
2
|
-
extend
|
2
|
+
extend self
|
3
|
+
def self.included(base) base.extend(self) end
|
3
4
|
|
4
|
-
def
|
5
|
+
def divider(template)
|
6
|
+
line_width = 150
|
7
|
+
line_width = line_width - $1.size if template =~ /(\s+)[=-]+/
|
8
|
+
template.gsub('+', "\n").gsub(/[-]+/, '-' * line_width).gsub(/[=]+/, '=' * line_width)
|
9
|
+
end
|
10
|
+
|
11
|
+
def log(msg='')
|
12
|
+
puts msg
|
13
|
+
end
|
14
|
+
|
15
|
+
def error(msg, command=nil)
|
16
|
+
puts divider '+-+'
|
17
|
+
puts 'ERROR '.format(:red,:bold) + msg
|
18
|
+
puts divider '-++'
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
|
22
|
+
def fmt(text, *args)
|
23
|
+
"#{fmt_start(*args)}#{text}#{fmt_end}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def fmt_start(*args)
|
5
27
|
effect = args.include?(:bold) ? 1 : 0
|
6
28
|
color = if args.include?(:red) then 31
|
7
29
|
elsif args.include?(:green) then 32
|
8
30
|
elsif args.include?(:magenta) then 35
|
9
31
|
else 39 end
|
10
|
-
"\033[#{effect};#{color}m
|
32
|
+
"\033[#{effect};#{color}m"
|
11
33
|
end
|
12
34
|
|
13
|
-
def
|
14
|
-
|
15
|
-
hash.symbolize_keys!
|
35
|
+
def fmt_end
|
36
|
+
"\033[0m"
|
16
37
|
end
|
17
38
|
|
18
|
-
def
|
19
|
-
puts '---------------------------------------------------------------------------------------------------------------'
|
20
|
-
puts 'OOPS'.format(:bold,:red) + '... unknown command'.format(:red)
|
21
|
-
puts Fanforce::CLI::Help.commands(@allowed_commands)
|
22
|
-
exit 1
|
23
|
-
end
|
24
|
-
|
25
|
-
def error(msg, command=nil)
|
26
|
-
puts '---------------------------------------------------------------------------------------------------------------'
|
27
|
-
puts 'ERROR... '.format(:bold,:red) + msg
|
28
|
-
puts '---------------------------------------------------------------------------------------------------------------'
|
29
|
-
puts ''
|
30
|
-
if command.present?
|
31
|
-
puts Fanforce::CLI::Help.for(command, @allowed_commands)
|
32
|
-
else
|
33
|
-
puts Fanforce::CLI::Help.commands(@allowed_commands)
|
34
|
-
end
|
35
|
-
exit 1
|
36
|
-
end
|
37
|
-
|
38
|
-
def confirm(msg)
|
39
|
-
puts '---------------------------------------------------------------------------------------------------------------'
|
39
|
+
def confirm(msg, exit_unless_confirmed=true)
|
40
40
|
print "#{msg} [y/n]: "
|
41
41
|
input = $stdin.gets.strip
|
42
|
-
|
42
|
+
confirmed = !input.downcase.include?('n')
|
43
|
+
(!confirmed && exit_unless_confirmed) ? exit(0) : confirmed
|
43
44
|
end
|
44
45
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
when :development then :dev
|
50
|
-
when :staging then :stg
|
51
|
-
when :production then :prd
|
52
|
-
else raise 'unknown environment'
|
53
|
-
end
|
54
|
-
is_symbol ? env : env.to_s
|
46
|
+
def prompt(msg, required=false)
|
47
|
+
print "#{msg}"
|
48
|
+
response = $stdin.gets.strip
|
49
|
+
(required && response.blank?) ? prompt(msg, required) : response
|
55
50
|
end
|
56
51
|
|
57
|
-
def
|
58
|
-
|
52
|
+
def find_cli_type(home_dir)
|
53
|
+
dir_names = home_dir.split('/')
|
54
|
+
types = {
|
55
|
+
directory_of_internals: false,
|
56
|
+
single_internal: false,
|
57
|
+
directory_of_apps: false,
|
58
|
+
single_app: false
|
59
|
+
}
|
60
|
+
|
61
|
+
types[:single_app] = true if File.exists?("#{home_dir}/config.json") and File.exists?("#{home_dir}/../.fanforce-app-factory")
|
62
|
+
types[:directory_of_apps] = true if File.exists?("#{home_dir}/.fanforce-app-factory")
|
63
|
+
|
64
|
+
if [dir_names[-1],dir_names[-2]].include?('Fanforce') && !File.exists?("#{home_dir}/.git") && !File.exists?("#{home_dir}/.fanforce-app-factory")
|
65
|
+
types[:directory_of_internals] = true
|
66
|
+
end
|
67
|
+
|
68
|
+
if [dir_names[-1],dir_names[-2],dir_names[-2]].include?('Fanforce') and File.exists?("#{home_dir}/.git") and !File.exists?("#{home_dir}/../.fanforce-app-factory")
|
69
|
+
types[:single_internal] = true
|
70
|
+
end
|
71
|
+
|
72
|
+
found_types = types.inject([]) {|found_types, (key,bool)| bool ? found_types << key : found_types }
|
73
|
+
|
74
|
+
if found_types.size != 1
|
75
|
+
divider '+-'
|
76
|
+
(found_types.size == 0) ? log('COULD NOT DEDUCE CLI TYPE') : log("CONFLICTING CLI TYPES: #{found_types.to_s}")
|
77
|
+
divider '+-'
|
78
|
+
exit
|
79
|
+
end
|
59
80
|
|
60
|
-
|
61
|
-
heroku_app_name.length > 30 ? heroku_app_name.gsub!(/(a|e|i|o|u)/, '') : heroku_app_name
|
81
|
+
return found_types.first
|
62
82
|
end
|
63
83
|
|
64
84
|
end
|
65
85
|
|
66
86
|
class String
|
67
87
|
def format(*args)
|
68
|
-
Fanforce::CLI::Utils.
|
88
|
+
Fanforce::CLI::Utils.fmt(self, *args)
|
69
89
|
end
|
70
90
|
end
|
data/lib/fanforce/cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,57 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fanforce-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: redis
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rest-client
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: iron_worker_ng
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
13
|
- !ruby/object:Gem::Dependency
|
56
14
|
name: activesupport
|
57
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,81 +25,24 @@ dependencies:
|
|
67
25
|
- !ruby/object:Gem::Version
|
68
26
|
version: '0'
|
69
27
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
28
|
+
name: fanforce-base
|
71
29
|
requirement: !ruby/object:Gem::Requirement
|
72
30
|
requirements:
|
73
|
-
- -
|
31
|
+
- - ~>
|
74
32
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
33
|
+
version: '1.2'
|
76
34
|
type: :runtime
|
77
35
|
prerelease: false
|
78
36
|
version_requirements: !ruby/object:Gem::Requirement
|
79
37
|
requirements:
|
80
|
-
- -
|
38
|
+
- - ~>
|
81
39
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
83
|
-
|
84
|
-
name: multi_json
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - '>='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - '>='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: bitbucket_rest_api
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - '>='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - '>='
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: fanforce
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - '>='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - '>='
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: fanforce-api
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - '>='
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :runtime
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - '>='
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
|
-
description: CLI for managing a folder of Fanforce apps
|
40
|
+
version: '1.2'
|
41
|
+
description:
|
140
42
|
email:
|
141
43
|
- cclark@mobilizationlabs.com
|
142
44
|
executables:
|
143
45
|
- fanforce
|
144
|
-
- fanforce-supercharge
|
145
46
|
extensions: []
|
146
47
|
extra_rdoc_files: []
|
147
48
|
files:
|
@@ -153,21 +54,15 @@ files:
|
|
153
54
|
- README.md
|
154
55
|
- Rakefile
|
155
56
|
- bin/fanforce
|
156
|
-
- bin/fanforce-supercharge
|
157
57
|
- fanforce-cli.gemspec
|
158
58
|
- lib/fanforce/cli.rb
|
159
|
-
- lib/fanforce/cli/
|
59
|
+
- lib/fanforce/cli/_load.rb
|
160
60
|
- lib/fanforce/cli/app.rb
|
161
61
|
- lib/fanforce/cli/apps.rb
|
162
|
-
- lib/fanforce/cli/
|
163
|
-
- lib/fanforce/cli/commands_support.rb
|
164
|
-
- lib/fanforce/cli/env.rb
|
165
|
-
- lib/fanforce/cli/files.rb
|
166
|
-
- lib/fanforce/cli/help.rb
|
167
|
-
- lib/fanforce/cli/run.rb
|
62
|
+
- lib/fanforce/cli/scripts/version.rb
|
168
63
|
- lib/fanforce/cli/utils.rb
|
169
64
|
- lib/fanforce/cli/version.rb
|
170
|
-
homepage:
|
65
|
+
homepage: http://github.com/fanforce/gem-fanforce-cli
|
171
66
|
licenses: []
|
172
67
|
metadata: {}
|
173
68
|
post_install_message:
|
@@ -181,13 +76,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
76
|
version: '0'
|
182
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
78
|
requirements:
|
184
|
-
- - '
|
79
|
+
- - '>'
|
185
80
|
- !ruby/object:Gem::Version
|
186
|
-
version:
|
81
|
+
version: 1.3.1
|
187
82
|
requirements: []
|
188
83
|
rubyforge_project:
|
189
84
|
rubygems_version: 2.0.14
|
190
85
|
signing_key:
|
191
86
|
specification_version: 4
|
192
|
-
summary:
|
87
|
+
summary: command-line interface for fanforce developers
|
193
88
|
test_files: []
|
89
|
+
has_rdoc:
|
data/bin/fanforce-supercharge
DELETED
data/lib/fanforce/cli/_base.rb
DELETED
@@ -1,263 +0,0 @@
|
|
1
|
-
require 'iron_worker_ng'
|
2
|
-
require 'fanforce/cli'
|
3
|
-
|
4
|
-
class Fanforce::CLI
|
5
|
-
require 'fanforce/cli/utils'
|
6
|
-
require 'fanforce/cli/files'
|
7
|
-
require 'fanforce/cli/app'
|
8
|
-
require 'fanforce/cli/apps'
|
9
|
-
require 'fanforce/cli/run'
|
10
|
-
require 'fanforce/cli/env'
|
11
|
-
require 'fanforce/cli/help'
|
12
|
-
require 'fanforce/cli/commands'
|
13
|
-
include Fanforce::CLI::Utils
|
14
|
-
|
15
|
-
def initialize(executable)
|
16
|
-
@executable = executable
|
17
|
-
$HomeDir = Shell.new.pwd
|
18
|
-
end
|
19
|
-
|
20
|
-
def start(options)
|
21
|
-
@runtype = options[:runtype]
|
22
|
-
@allowed_commands = options[:allowed]
|
23
|
-
setup_config
|
24
|
-
init_counter(Process.pid) if @runtype == :forked
|
25
|
-
parse_app_filter
|
26
|
-
parse_command
|
27
|
-
destroy_counter(Process.pid) if @runtype == :forked
|
28
|
-
end
|
29
|
-
|
30
|
-
def setup_config
|
31
|
-
puts 'ERROR: Fanforce CLI could not find the required config file.'.format(:red) if !File.exists?("#{$HomeDir}/.fanforce-cli")
|
32
|
-
$Config = format_config(YAML.load_file("#{$HomeDir}/.fanforce-cli"))
|
33
|
-
end
|
34
|
-
|
35
|
-
def parse_app_filter
|
36
|
-
if ARGV[0] =~ /^:((app)-(.+))$/
|
37
|
-
$Filter = {dir_name: $1}
|
38
|
-
ARGV.shift
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
#################################################################################
|
43
|
-
|
44
|
-
def parse_command
|
45
|
-
|
46
|
-
#################################################################
|
47
|
-
|
48
|
-
if ARGV.length == 0 or !@allowed_commands.include?(ARGV[0].to_sym)
|
49
|
-
puts Fanforce::CLI::Help.intro(@executable, @runtype)
|
50
|
-
puts Fanforce::CLI::Help.commands(@allowed_commands)
|
51
|
-
|
52
|
-
#################################################################
|
53
|
-
|
54
|
-
elsif ARGV[0] == 'list'
|
55
|
-
list_apps
|
56
|
-
|
57
|
-
#################################################################
|
58
|
-
|
59
|
-
elsif ARGV[0] == 'create'
|
60
|
-
ARGV[1] =~ /^app-([a-z0-9-]+)$/i || error('You supplied an invalid create command.', :create)
|
61
|
-
create_app($1)
|
62
|
-
|
63
|
-
#################################################################
|
64
|
-
|
65
|
-
elsif ARGV[0] == 'update'
|
66
|
-
ARGV[1] =~ /^(all|files|bundle|pow|get|env)$/i || error('You supplied an invalid update command.', :update)
|
67
|
-
run(:update, $1.to_sym)
|
68
|
-
|
69
|
-
#################################################################
|
70
|
-
|
71
|
-
elsif ARGV[0] == 'delete'
|
72
|
-
ARGV[1] =~ /^app-([a-z0-9-]+)$/ || error('You supplied an invalid delete command.', :delete)
|
73
|
-
confirm("Are you sure you want to delete all files, repositories, and other items for #{ARGV[1]}?")
|
74
|
-
delete_app($1)
|
75
|
-
|
76
|
-
#################################################################
|
77
|
-
|
78
|
-
elsif ARGV[0] == 'push'
|
79
|
-
ARGV[1] =~ /^(all|development|staging|production)$/i || error('You supplied an invalid push command.', :push)
|
80
|
-
environment = $1.to_sym
|
81
|
-
|
82
|
-
ARGV[2] =~ /^(all|heroku|iron|bitbucket)$/i || error('You supplied an invalid push command.', :push)
|
83
|
-
command = $1.to_sym
|
84
|
-
|
85
|
-
confirm('Are you sure you want to push to all environments, including production?') if environment == :all
|
86
|
-
confirm('Are you sure you want to push to production?') if environment == :production
|
87
|
-
confirm("Are you sure you want to push to all services on #{environment}?") if command == :all
|
88
|
-
|
89
|
-
run(:push, environment, command)
|
90
|
-
|
91
|
-
#################################################################
|
92
|
-
|
93
|
-
elsif ARGV[0] == 'restart'
|
94
|
-
if ARGV[1].present?
|
95
|
-
ARGV[1] =~ /^(development|staging|production|all)?$/ || error('You supplied an invalid restart command.', :restart)
|
96
|
-
environment = $1.to_sym
|
97
|
-
else
|
98
|
-
environment = :development
|
99
|
-
end
|
100
|
-
|
101
|
-
confirm('Are you sure you want to restart all environments?') if environment == :all
|
102
|
-
run(:restart, environment)
|
103
|
-
|
104
|
-
#################################################################
|
105
|
-
|
106
|
-
elsif ARGV[0] == 'count'
|
107
|
-
count
|
108
|
-
|
109
|
-
#################################################################
|
110
|
-
|
111
|
-
elsif ARGV[0] == 'bundle'
|
112
|
-
ARGV[1] =~ /^(install|update)$/ || error('You supplied an invalid bundle command.', :bundle)
|
113
|
-
|
114
|
-
run(:bundle, $1.to_sym, ARGV[3..-1] || [])
|
115
|
-
|
116
|
-
#################################################################
|
117
|
-
|
118
|
-
elsif ARGV[0] == 'git' and ARGV[1] == 'status:overview'
|
119
|
-
run(:git_overview)
|
120
|
-
|
121
|
-
elsif ARGV[0] == 'git'
|
122
|
-
run(:git, ARGV[1..-1] || [])
|
123
|
-
|
124
|
-
#################################################################
|
125
|
-
|
126
|
-
elsif ARGV[0] == 'iron'
|
127
|
-
ARGV[1] =~ /^(upload|reset|delete)$/i || error('You supplied an invalid iron command.', :iron)
|
128
|
-
command = $1.to_sym
|
129
|
-
|
130
|
-
ARGV[2] =~ /^(all|development|staging|production)$/i || error('You supplied an invalid iron environment.', :iron)
|
131
|
-
environment = $1.to_sym
|
132
|
-
confirm("Are you sure you want to #{command} workers in all environments?") if environment == :all
|
133
|
-
|
134
|
-
if command == :delete
|
135
|
-
delete_all_iron_workers(environment)
|
136
|
-
else
|
137
|
-
run(:iron, command, environment)
|
138
|
-
end
|
139
|
-
|
140
|
-
#################################################################
|
141
|
-
|
142
|
-
elsif ARGV[0] == 'cleanorgs'
|
143
|
-
ARGV[1] =~ /^(development|staging|production)$/ || error('You supplied an invalid cleanorgs command.', :cleanorgs)
|
144
|
-
environment = $1.to_sym
|
145
|
-
|
146
|
-
supercore_api_key = ARGV[2] || error('You supplied an invalid cleanorgs command.', :cleanorgs)
|
147
|
-
|
148
|
-
run(:cleanorgs, environment, supercore_api_key)
|
149
|
-
|
150
|
-
#################################################################
|
151
|
-
|
152
|
-
elsif ARGV[0] == 'version'
|
153
|
-
puts '---------------------------------------------------------------------------------------------------------------'
|
154
|
-
puts "You are using version #{Fanforce::CLI::VERSION} of Fanforce CLI"
|
155
|
-
puts '---------------------------------------------------------------------------------------------------------------'
|
156
|
-
|
157
|
-
elsif ARGV[0] == 'config'
|
158
|
-
puts '---------------------------------------------------------------------------------------------------------------'
|
159
|
-
if !File.exists?("#{$HomeDir}/.fanforce-cli")
|
160
|
-
puts 'Oops'.format(:red,:bold) + '... no ".fanforce-cli" file was found in this directory.'.format(:red)
|
161
|
-
else
|
162
|
-
puts $Config
|
163
|
-
end
|
164
|
-
puts '---------------------------------------------------------------------------------------------------------------'
|
165
|
-
|
166
|
-
elsif ARGV[0] == 'upgrade'
|
167
|
-
run(:upgrade)
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
#################################################################################
|
174
|
-
|
175
|
-
def run(method, *args)
|
176
|
-
(@runtype == :forked) ? run_forked(method, *args) : run_multiple(method, *args)
|
177
|
-
end
|
178
|
-
|
179
|
-
def run_multiple(method, *args)
|
180
|
-
if (dirs = Apps.dirs).size == 0
|
181
|
-
puts "\n---------------------------------------------------------------------------------------------------------------"
|
182
|
-
puts "#{'Oops'.format(:bold)}... no fanforce apps were found in this directory."
|
183
|
-
puts "---------------------------------------------------------------------------------------------------------------\n"
|
184
|
-
return
|
185
|
-
end
|
186
|
-
|
187
|
-
if self.respond_to?(:"preprocess_#{method}")
|
188
|
-
args << self.method(:"preprocess_#{method}").call
|
189
|
-
end
|
190
|
-
Apps.each do |app, processed_count, total_count|
|
191
|
-
self.method(:"run_#{method}").call(app.dir, processed_count, total_count, *args)
|
192
|
-
end
|
193
|
-
if self.respond_to?(:"postprocess_#{method}")
|
194
|
-
self.method(:"postprocess_#{method}").call
|
195
|
-
else
|
196
|
-
puts "\n---------------------------------------------------------------------------------------------------------------"
|
197
|
-
puts 'DONE!'
|
198
|
-
puts '---------------------------------------------------------------------------------------------------------------'
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def run_forked(method, *args)
|
203
|
-
counter_id = Process.pid
|
204
|
-
processes = []
|
205
|
-
dirs = Apps.dirs
|
206
|
-
puts "\n---------------------------------------------------------------------------------------------------------------"
|
207
|
-
dirs.each_with_index do |app_dir, i|
|
208
|
-
puts "#{'Forking'.format(:white,:bold)} #{app_dir}"
|
209
|
-
end
|
210
|
-
dirs.each_with_index do |app_dir, i|
|
211
|
-
processes << fork do
|
212
|
-
response = capture_stdout do
|
213
|
-
self.method(:"run_#{method}").call(app_dir, 'PROCESSED_APPS_COUNT', dirs.size, *args)
|
214
|
-
end
|
215
|
-
puts response.gsub('PROCESSED_APPS_COUNT', incr_counter(counter_id).to_s)
|
216
|
-
end
|
217
|
-
sleep(0.25)
|
218
|
-
end
|
219
|
-
|
220
|
-
processes.each { |pid| Process.waitpid(pid) }
|
221
|
-
puts "\n---------------------------------------------------------------------------------------------------------------"
|
222
|
-
puts 'DONE!'
|
223
|
-
puts '---------------------------------------------------------------------------------------------------------------'
|
224
|
-
end
|
225
|
-
|
226
|
-
require 'stringio'
|
227
|
-
def capture_stdout
|
228
|
-
previous_stdout, previous_stderr = $stdout, $stderr
|
229
|
-
io = StringIO.new
|
230
|
-
$stdout = io
|
231
|
-
$stderr = io
|
232
|
-
IronCore::Logger.logger = ::Logger.new(io)
|
233
|
-
IronCore::Logger.logger.level = ::Logger::INFO
|
234
|
-
yield
|
235
|
-
io.string
|
236
|
-
ensure
|
237
|
-
$stdout = previous_stdout
|
238
|
-
$stderr = previous_stderr
|
239
|
-
end
|
240
|
-
|
241
|
-
def init_counter(counter_id)
|
242
|
-
File.open("#{$HomeDir}/.forked-counter-#{counter_id}", 'w') {|f| f.write('0') }
|
243
|
-
end
|
244
|
-
|
245
|
-
def incr_counter(counter_id)
|
246
|
-
new_count = nil
|
247
|
-
File.open("#{$HomeDir}/.forked-counter-#{counter_id}", File::RDWR|File::CREAT, 0644) do |f|
|
248
|
-
f.flock(File::LOCK_EX)
|
249
|
-
new_count = f.read.to_i + 1
|
250
|
-
f.rewind
|
251
|
-
f.write("#{new_count}\n")
|
252
|
-
f.flush
|
253
|
-
f.truncate(f.pos)
|
254
|
-
end
|
255
|
-
new_count
|
256
|
-
end
|
257
|
-
|
258
|
-
def destroy_counter(counter_id)
|
259
|
-
File.delete("#{$HomeDir}/.forked-counter-#{counter_id}")
|
260
|
-
end
|
261
|
-
|
262
|
-
end
|
263
|
-
|