fanforce-cli 1.7.1 → 2.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42c4873bb599d4f3f889d47901b18f4b6d4f03b9
4
- data.tar.gz: fe2f8930277bec0d1a860d3dbaf0e191e91d3734
3
+ metadata.gz: 4d77a2b3fde1139385186a6bf61a894d4e0bcc75
4
+ data.tar.gz: 087070dc87ad1127e0743cab3f3a7b1043fd79e6
5
5
  SHA512:
6
- metadata.gz: c9e7bcf5ed5275f458567814cb0f96a794d20b13483bf842f8c711f9629ff7c8efb116e3cd7c3b7c461d3ab7f4da2ed7810a343a4f0524775a8fc1a5de2af483
7
- data.tar.gz: 77a079d7a5b05e090eb3b34925bfe77ed450f1d68ea1d05499cb2ff97857482305853b1ab10caf31cbdce70d43a948259455d58daf9abd4408609884c3f70577
6
+ metadata.gz: 6cc548a9940a6925b881c5f83ee5aaa9792ba8bb99838e36a6e3b5d5ec750fab85bac3306ca1768e804bff588bcd1db6d3430ebb127c2bf76c191e1b600c3327
7
+ data.tar.gz: 398dfd0ab93eb0225cf9154db80bf82597b49f3eb91d8560dcb925f790be6b50f6daa2275f97156045c4c921febc4e05d23b862259fee34777935d9bb174c009
data/Gemfile.lock CHANGED
@@ -1,85 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fanforce-cli (1.0.0)
4
+ fanforce-cli (2.0.0.rc1)
5
5
  activesupport
6
- bitbucket_rest_api
7
- fanforce-api
8
- heroku-api (= 0.3.8)
9
- iron_worker_ng
10
- multi_json
11
- redis
12
- rest-client
6
+ fanforce-base (~> 1.2)
13
7
 
14
8
  GEM
15
9
  remote: https://rubygems.org/
16
10
  specs:
17
- activesupport (4.1.4)
11
+ activesupport (4.1.8)
18
12
  i18n (~> 0.6, >= 0.6.9)
19
13
  json (~> 1.7, >= 1.7.7)
20
14
  minitest (~> 5.1)
21
15
  thread_safe (~> 0.1)
22
16
  tzinfo (~> 1.1)
23
- activesupport-inflector (0.1.0)
24
- bitbucket_rest_api (0.1.5)
25
- faraday (~> 0.8.1)
26
- faraday_middleware (~> 0.9.0)
27
- hashie (~> 2.0.5)
28
- multi_json (~> 1.3)
29
- nokogiri (>= 1.5.2)
30
- simple_oauth
31
- excon (0.16.10)
32
- fanforce (0.19.0)
33
- multi_json (>= 1.7.2)
17
+ addressable (2.3.6)
18
+ fanforce-base (1.2.2)
19
+ addressable (~> 2.3.6)
34
20
  rack
35
- fanforce-api (0.23.0)
36
- fanforce-exceptions (~> 0.5)
37
- fanforce-validations (~> 0.7)
38
- rest-client (~> 1.6.7)
39
- fanforce-exceptions (0.5.1)
40
- fanforce (~> 0.15)
41
- fanforce-validations (0.7.1)
42
- activesupport-inflector (~> 0.1)
43
- fanforce (~> 0.15)
44
- fanforce-exceptions (~> 0.5)
45
- faraday (0.8.9)
46
- multipart-post (~> 1.2.0)
47
- faraday_middleware (0.9.1)
48
- faraday (>= 0.7.4, < 0.10)
49
- hashie (2.0.5)
50
- heroku-api (0.3.8)
51
- excon (~> 0.16.10)
52
21
  i18n (0.6.11)
53
- iron_core (1.0.5)
54
- rest (>= 2.6.4)
55
- iron_worker_ng (1.5.0)
56
- bundler
57
- iron_core (>= 1.0.0)
58
- rubyzip (= 0.9.9)
59
22
  json (1.8.1)
60
- mime-types (1.25.1)
61
- mini_portile (0.6.0)
62
- minitest (5.4.0)
63
- multi_json (1.10.1)
64
- multipart-post (1.2.0)
65
- net-http-persistent (2.9.4)
66
- netrc (0.7.7)
67
- nokogiri (1.6.3.1)
68
- mini_portile (= 0.6.0)
23
+ minitest (5.4.3)
69
24
  rack (1.5.2)
70
- rdoc (4.1.1)
71
- json (~> 1.4)
72
- redis (3.1.0)
73
- rest (2.7.2)
74
- net-http-persistent (>= 2.9.1)
75
- rest_client (>= 1.7.1)
76
- rest-client (1.6.8)
77
- mime-types (~> 1.16)
78
- rdoc (>= 2.4.2)
79
- rest_client (1.7.3)
80
- netrc (~> 0.7.7)
81
- rubyzip (0.9.9)
82
- simple_oauth (0.2.0)
83
25
  thread_safe (0.3.4)
84
26
  tzinfo (1.2.2)
85
27
  thread_safe (~> 0.1)
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
data/bin/fanforce CHANGED
@@ -1,20 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'fanforce/cli'
3
3
 
4
- fanforce = Fanforce::CLI.new('fanforce')
5
-
6
- if File.exists?("#{$HomeDir}/config.ru") and File.exists?("#{$HomeDir}/../.fanforce-cli")
7
- ARGV.unshift(":#{File.basename($HomeDir)}")
8
- $HomeDir = File.expand_path('..', $HomeDir)
9
- fanforce.start(
10
- :runtype => :single,
11
- :allowed => [:update, :push, :restart, :bundle, :git, :iron, :version, :config, :cleanorgs, :upgrade],
12
- )
13
- elsif File.exists?("#{$HomeDir}/.fanforce-cli")
14
- fanforce.start(
15
- :runtype => :multiple,
16
- :allowed => [:list, :create, :delete, :update, :push, :restart, :count, :bundle, :git, :iron, :version, :config, :cleanorgs, :upgrade],
17
- )
18
- else
19
- puts 'NOT A VALID DIRECTORY'
20
- end
4
+ Fanforce::CLI.new('fanforce', :standard)
data/fanforce-cli.gemspec CHANGED
@@ -2,30 +2,22 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'fanforce/cli/version'
5
- require 'rubygems'
6
5
 
7
6
  Gem::Specification.new do |gem|
8
- gem.name = 'fanforce-cli'
9
- gem.version = Fanforce::CLI::VERSION
10
- gem.authors = ['Caleb Clark']
11
- gem.email = ['cclark@mobilizationlabs.com']
12
- gem.description = %q{CLI for managing a folder of Fanforce apps}
13
- gem.summary = %q{Manage a folder of Fanforce apps}
14
- gem.homepage = ''
7
+ gem.name = 'fanforce-cli'
8
+ gem.version = Fanforce::CLI::VERSION
9
+ gem.date = Time.now.utc.strftime('%Y-%m-%d')
10
+ gem.summary = %q{command-line interface for fanforce developers}
11
+
12
+ gem.authors = ['Caleb Clark']
13
+ gem.email = ['cclark@mobilizationlabs.com']
14
+ gem.homepage = 'http://github.com/fanforce/gem-fanforce-cli'
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
17
- gem.executables = ['fanforce','fanforce-supercharge']
17
+ gem.executables = ['fanforce'] #,'fanforce-supercharge'
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ['lib']
20
20
 
21
- gem.add_dependency 'redis'
22
- gem.add_dependency 'rest-client'
23
- gem.add_dependency 'iron_worker_ng'
24
21
  gem.add_dependency 'activesupport'
25
- gem.add_dependency 'heroku-api', '0.3.8'
26
- gem.add_dependency 'multi_json'
27
- gem.add_dependency 'bitbucket_rest_api'
28
- gem.add_dependency 'fanforce'
29
- gem.add_dependency 'fanforce-api'
30
-
22
+ gem.add_dependency 'fanforce-base', '~> 1.2'
31
23
  end
data/lib/fanforce/cli.rb CHANGED
@@ -1,12 +1,7 @@
1
- require 'active_support/all'
2
- require 'optparse'
3
- require 'shell'
4
- require 'rest-client'
5
- require 'multi_json'
6
- require 'bitbucket_rest_api'
7
- require 'heroku-api'
8
- require 'yaml'
9
- require 'fanforce'
1
+ require 'fanforce/base'
10
2
 
11
3
  require_relative 'cli/version'
12
- require_relative 'cli/_base'
4
+ require_relative 'cli/utils'
5
+ require_relative 'cli/app'
6
+ require_relative 'cli/apps'
7
+ require_relative 'cli/_load'
@@ -0,0 +1,177 @@
1
+ require 'active_support/all'
2
+ require 'shell'
3
+ require 'fanforce/cli/utils'
4
+
5
+ class Fanforce::CLI
6
+ include Fanforce::CLI::Utils
7
+
8
+ DIR = Shell.new.pwd
9
+ TYPE = Fanforce::CLI::Utils.find_cli_type(DIR)
10
+
11
+ @@commands = {}
12
+ @@docs = []
13
+ @@has_finished_loading_internal_commands = false
14
+
15
+ def initialize(executable, runtype)
16
+ @executable = executable
17
+ @runtype = runtype
18
+
19
+ start_spinner
20
+ load_cli_commands
21
+ end
22
+
23
+ def start_spinner
24
+ @spinner_output = ''
25
+ @spinner = Thread.new do
26
+ print @spinner_output
27
+ i = 0
28
+ loop do
29
+ i += 1
30
+ if (i%100) == 0
31
+ print ("\b"*@spinner_output.size) + (' '*@spinner_output.size) + ("\b"*@spinner_output.size)
32
+ @spinner_output = ''
33
+ else
34
+ @spinner_output += '.'
35
+ print '.'
36
+ end
37
+ sleep 0.1
38
+ end
39
+ end
40
+ end
41
+
42
+ def stop_spinner
43
+ Thread.kill(@spinner)
44
+ print ("\b"*@spinner_output.size) + (' '*@spinner_output.size) + ("\b"*@spinner_output.size)
45
+ end
46
+
47
+ def get_parent_dir(current_dir)
48
+ File.expand_path('..', current_dir)
49
+ end
50
+
51
+ def load_cli_commands
52
+ require_relative 'scripts/version'
53
+
54
+ if TYPE == :directory_of_apps
55
+ begin
56
+ require 'fanforce/app_factory/cli_directory_of_apps'
57
+ rescue LoadError => e
58
+ raise if !e.message.include?('fanforce/app_factory/cli_directory_of_apps')
59
+ error('You must install the fanforce-app-factory gem (> 2.0) for use in this folder')
60
+ end
61
+ elsif TYPE == :single_app
62
+ begin
63
+ require 'fanforce/app_factory/cli_single_app'
64
+ rescue LoadError => e
65
+ raise if !e.message.include?('fanforce/app_factory/cli_single_app')
66
+ error('You must install the fanforce-app-factory gem (> 2.0) for use in an app folder')
67
+ end
68
+ end
69
+
70
+ @@has_finished_loading_internal_commands = true
71
+
72
+ dir_to_check = Dir.pwd
73
+ while dir_to_check do
74
+ cli_scripts_dir = "#{dir_to_check}/.cli-scripts"
75
+ Dir["#{cli_scripts_dir}/*.rb"].each {|f| require f } if File.directory?(cli_scripts_dir)
76
+ break if dir_to_check == '/'
77
+ dir_to_check = get_parent_dir(dir_to_check)
78
+ end
79
+
80
+ print_docs_and_exit if ARGV.size == 0
81
+
82
+ command = @@commands[ARGV.shift.to_sym] || (error 'Unknown command')
83
+ run(command, *ARGV)
84
+ end
85
+
86
+ def self.register(klass, command, *raw_docs, &block)
87
+ path_to_caller = caller[0].split(':')[0]
88
+ if @@commands[command]
89
+ error("Trying to register \"#{command}\" command, but it has already been registered...\n" +
90
+ " 1st: #{@@commands[command][:path_to_caller]}\n" +
91
+ " 2nd: #{path_to_caller}"
92
+ )
93
+ end
94
+ error "#{command} is missing docs" if raw_docs.size == 0
95
+ if raw_docs.size == 1
96
+ raw_doc = raw_docs[0]
97
+ doc_columns = (raw_doc[0] || '').strip.split(/\s+/)
98
+ doc_columns.fill('', doc_columns.size...2) if doc_columns.size < 2
99
+ doc_columns.push(raw_doc[1])
100
+ rows = [doc_columns]
101
+ else
102
+ rows = []
103
+ raw_docs.each do |raw_doc|
104
+ next if !raw_doc
105
+ doc_columns = (raw_doc[0] || '').strip.split(/\s+/)
106
+ doc_columns.fill('', doc_columns.size...2) if doc_columns.size < 2
107
+ doc_columns.push(raw_doc[1])
108
+ rows << doc_columns
109
+ end
110
+ end
111
+ doc = {command: command, rows: rows, is_local: @@has_finished_loading_internal_commands || false}
112
+ @@docs << doc
113
+ @@commands[command] = {klass: klass, method: command, block: block, doc: doc, path_to_caller: path_to_caller}
114
+ end
115
+
116
+ def print_docs_and_exit
117
+ commands = []
118
+ local_commands = []
119
+ @@docs.each do |doc|
120
+ tmp_column1 = nil
121
+ doc[:rows].each_with_index do |columns, row_i|
122
+ columns.unshift(row_i==0 ? doc[:command] : '')
123
+ columns[1]==tmp_column1 ? columns[1] = '' : tmp_column1 = columns[1] if doc[:rows].size > 1
124
+ doc[:is_local] ? local_commands << columns : commands << columns
125
+ end
126
+ end
127
+
128
+ running_as = TYPE.to_s.gsub('_', ' ')
129
+ formatted_docs = divider '-+'
130
+ formatted_docs += sprintf("%-#{122-running_as.length}s (%#{running_as.length}s)", 'USAGE: fanforce <command>', running_as)
131
+
132
+ formatted_docs += "\n\n\nFACTORY COMMANDS..."
133
+
134
+ format_command = lambda {|columns|
135
+ formatted_docs += divider '+-' if columns[0].present?
136
+ if columns[2].present?
137
+ template = "\n%-12s %-15s %-25s %-50s"
138
+ else
139
+ columns.delete_at(2)
140
+ template = "\n%-12s %-41s %-50s"
141
+ end
142
+ formatted_docs += sprintf(template, *columns)
143
+ }
144
+
145
+ commands.each {|columns| format_command.call(columns.clone) }
146
+
147
+ if local_commands.size > 0
148
+ formatted_docs += divider '+-+++'
149
+ formatted_docs += 'LOCAL COMMANDS...'
150
+ local_commands.each {|columns| format_command.call(columns.clone) }
151
+ end
152
+
153
+ formatted_docs += divider '+-+++'
154
+ stop_spinner
155
+ puts formatted_docs
156
+ exit
157
+ end
158
+
159
+ ######################################################################################################################
160
+
161
+ def run(command, *args)
162
+ command[:block].call if command[:block]
163
+ stop_spinner
164
+ self.method("run_#{@runtype}").call(command[:klass], command[:method], *args)
165
+ end
166
+
167
+ def run_standard(klass, method, *args)
168
+ instance = klass.new
169
+ instance.send(method, *args)
170
+ rescue ArgumentError => e
171
+ arity = instance.method(method).arity
172
+ raise if (arity >= 0 and arity == args.size) or ((arity < 0) and arity < -args.size)
173
+ error "Incorrect command for #{method}: #{e.message}", method
174
+ end
175
+
176
+ end
177
+
@@ -1,44 +1,42 @@
1
1
  class Fanforce::CLI::App
2
- attr_reader :_id, :dir, :dir_name, :dir_root, :root_domain
2
+
3
+ attr_reader :_id, :dir, :dir_name, :dir_root, :root_domain, :name
3
4
 
4
5
  def self.parse_dir_name(dir_name)
5
6
  return if dir_name !~ /^(app-([a-z0-9-]+))\/?$/
6
7
  {_id: $2, dir_name: $1}
7
8
  end
8
9
 
9
- def self.load(dir)
10
- self.new(dir)
11
- end
10
+ def self.load(dir); self.new(dir) end
11
+
12
+ ######################################################################################################################
12
13
 
13
14
  def initialize(dir)
14
- raise "This is an invalid directory name for a fanforce addon: #{dir}" if dir !~ /^(.*)\/(app-([a-z0-9-]+))\/?$/
15
- @_id = $3
15
+ raise "This is an invalid directory name for a fanforce addon: #{dir}" if dir !~ /^(.*)\/([a-z0-9-]+)\/?$/
16
+ @_id = $2
16
17
  @dir = "#{$1}/#{$2}"
17
18
  @dir_root = $1
18
19
  @dir_name = $2
19
20
  @root_domain = Fanforce.apps_base_domain
21
+ @name = @_id.gsub('-', ' ').titleize
20
22
  end
21
23
 
22
- def create_files(*filenames)
23
- filenames.each do |filename|
24
- Fanforce::CLI::Files.method(:"create_#{filename}").call(self)
25
- end
26
- end
27
- alias create_file create_files
28
-
29
- def update_files(*filenames)
30
- filenames.each do |filename|
31
- Fanforce::CLI::Files.method(:"update_#{filename}").call(self)
24
+ def config
25
+ @config ||= begin
26
+ file_path = "#{@dir}/config.json"
27
+ return {} if !File.exists?(file_path)
28
+ file = File.open(file_path).read
29
+ MultiJson.load(file, symbolize_keys: true)
32
30
  end
33
31
  end
34
- alias update_file update_files
35
32
 
36
33
  def to_hash
37
34
  {
38
35
  _id: @_id,
36
+ name: @name,
39
37
  dir_name: @dir_name,
40
38
  dir_root: @dir_root,
41
- dir: @dir,
39
+ dir: @dir
42
40
  }
43
41
  end
44
42
 
@@ -46,12 +44,4 @@ class Fanforce::CLI::App
46
44
  to_hash.to_json
47
45
  end
48
46
 
49
- def start_print
50
- print "- #{@dir_name}... "
51
- end
52
-
53
- def end_print
54
- puts 'DONE'
55
- end
56
-
57
47
  end
@@ -1,41 +1,32 @@
1
1
  class Fanforce::CLI::Apps
2
- require 'singleton'
3
- require 'forwardable'
4
- include Singleton
5
2
 
6
- def dir_names
7
- @dirs ||= Dir.chdir($HomeDir) do Dir['*/'].inject([]) do |dirs, d|
3
+ @@dirs = nil
4
+
5
+ def self.dir_names
6
+ @@dirs ||= Dir.chdir(Fanforce::CLI::DIR) do Dir['*/'].inject([]) do |dirs, d|
8
7
  d = d.gsub('/', '')
9
- next dirs if d !~ /^(app-[a-z0-9-]+)\/?$/
10
- next dirs << d if $Filter.blank?
11
- next dirs << d if $Filter[:dir_name].present? and $Filter[:dir_name] == d
12
- next dirs
8
+ (d =~ /^([a-z0-9-]+)\/?$/) ? dirs << d : dirs
13
9
  end end
14
10
  end
15
11
 
16
- def dirs
12
+ def self.dirs
17
13
  dir_names.inject([]) do |result, d|
18
- result << "#{$HomeDir}/#{d}"
14
+ result << "#{Fanforce::CLI::DIR}/#{d}"
19
15
  end
20
16
  end
21
17
 
22
- def each(&block)
18
+ def self.each(&block)
23
19
  cur_count = 0
24
20
  total = dir_names.size
25
21
  dir_names.each do |d|
26
22
  cur_count += 1
27
- app = Fanforce::CLI::App.load("#{$HomeDir}/#{d}")
23
+ app = Fanforce::CLI::App.load("#{Fanforce::CLI::DIR}/#{d}")
28
24
  Dir.chdir(app.dir) { block.call(app, cur_count, total) }
29
25
  end
30
26
  end
31
27
 
32
- def count
28
+ def self.count
33
29
  dir_names.size
34
30
  end
35
31
 
36
- class << self
37
- extend Forwardable
38
- def_delegators :instance, *Fanforce::CLI::Apps.instance_methods(false)
39
- end
40
-
41
32
  end