xcskarel 0.2.1 → 0.3

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: f7bdf2a85953756731e78aae428a424575650427
4
- data.tar.gz: fab818d67d646bc86e4d6827303f0d0b858ba86a
3
+ metadata.gz: f0c5a62e07ba83314f4c8837c2994722d02285cd
4
+ data.tar.gz: 497b7601779a4f216aa0c8be5dfdd214daa298c2
5
5
  SHA512:
6
- metadata.gz: bd33c4eac88e8eca1503cdd0aa28489d0469d488be44b981a19e34eb0cfbd5a06164eb83a8c49295bc1efdc77e2d16108abc036de74af62442a6b40662075db0
7
- data.tar.gz: e3f755f5a99976bcef8f973df9a50a229e1f6ba813204cefcaddadcfe97c04a1e5ddc5599fc2661676959041c3f09fcc88a72aef3c5fe0f6fbfc8803251a8ffa
6
+ metadata.gz: 248a370dca81fa6ef007d94b2de6320b2738c3eef8cd26d6917644462ca0e61b6ddd6afdddffc3f8371fdcb7a622591879729850c3800f075368f7a71cf00382
7
+ data.tar.gz: c67fe583a47c9336d169cd357891d9e8f5110393057dbe934dd5545a44ab23c8b5613cbb0c0e98bdf23c77088cf48b5c63ca65c8231181c24c52c09bd07adfa5
data/bin/xcskarel CHANGED
@@ -68,6 +68,68 @@ class XCSKarelApplication
68
68
  end
69
69
  end
70
70
 
71
+ command :'server start' do |c|
72
+ c.syntax = 'xcskarel server start [options]'
73
+ c.description = 'Start local Xcode Server'
74
+ c.example 'start xcode server', 'xcskarel server start --path /Applications/Xcode.app'
75
+ c.option '--path XCODE_PATH', 'Xcode path'
76
+ c.action do |args, options|
77
+ xcode = options.path
78
+ unless options.path
79
+ xcodes = XCSKarel::Control.installed_xcodes
80
+ raise "No Xcode found, please provide --path" if xcodes.count == 0
81
+ if xcodes.count > 1
82
+ choice = choose("Select Xcode version", *xcodes)
83
+ xcode = choice
84
+ else
85
+ xcode = xcodes.first
86
+ end
87
+ end
88
+
89
+ XCSKarel::Control.start(xcode)
90
+ end
91
+ end
92
+
93
+ command :'server stop' do |c|
94
+ c.syntax = 'xcskarel server stop'
95
+ c.description = 'Stop local Xcode Server'
96
+ c.example 'stop xcode server', 'xcskarel server stop'
97
+ c.action do |args, options|
98
+ XCSKarel::Control.stop
99
+ end
100
+ end
101
+
102
+ command :'server restart' do |c|
103
+ c.syntax = 'xcskarel server restart'
104
+ c.description = 'Restart local Xcode Server'
105
+ c.example 'restart xcode server', 'xcskarel server restart'
106
+ c.action do |args, options|
107
+ XCSKarel::Control.restart
108
+ end
109
+ end
110
+
111
+ command :'server reset' do |c|
112
+ c.syntax = 'xcskarel server reset'
113
+ c.description = 'Reset local Xcode Server (!!! Deletes all local Bots & Integrations !!!)'
114
+ c.example 'reset xcode server', 'xcskarel server reset'
115
+ c.action do |args, options|
116
+ resp = agree("Are you sure you want to reset your local Xcode Server? This will delete all local Bots and Integrations! (y/n)".red)
117
+ XCSKarel::Control.reset if resp
118
+ end
119
+ end
120
+
121
+ command :'xcode select' do |c|
122
+ c.syntax = 'xcskarel xcode select'
123
+ c.description = 'Interactive xcode-select'
124
+ c.example 'choose xcode', 'xcskarel xcode select'
125
+ c.action do |args, options|
126
+ xcodes = XCSKarel::Control.installed_xcodes
127
+ raise "No Xcode found" if xcodes.count == 0
128
+ xcode = choose("Select Xcode version", *xcodes)
129
+ XCSKarel::Control.select(xcode)
130
+ end
131
+ end
132
+
71
133
  run!
72
134
  end
73
135
  end
@@ -0,0 +1,67 @@
1
+
2
+ module XCSKarel
3
+ module Control
4
+ def self.installed_xcodes
5
+ unless (`mdutil -s /` =~ /disabled/).nil?
6
+ # indexing is turned off
7
+ return nil
8
+ end
9
+
10
+ status, output = self.execute('mdfind "kMDItemCFBundleIdentifier == \'com.apple.dt.Xcode\'" 2>/dev/null')
11
+ raise "Failed to fetch Xcode paths: #{output}" if status != 0
12
+ output.split("\n")
13
+ end
14
+
15
+ def self.start(xcode)
16
+ raise "No Xcode path provided" unless xcode
17
+
18
+ self.select(xcode)
19
+
20
+ XCSKarel.log.info "Starting Xcode Server... This may take up to a minute.".yellow
21
+
22
+ self.exec_sudo("sudo xcrun xcscontrol --initialize")
23
+ self.exec_sudo("sudo xcrun xcscontrol --preflight")
24
+
25
+ XCSKarel.log.info "Xcode Server started & running on localhost now!".green
26
+ end
27
+
28
+ def self.stop
29
+ self.exec_sudo("sudo xcrun xcscontrol --shutdown")
30
+ end
31
+
32
+ def self.restart
33
+ self.exec_sudo("sudo xcrun xcscontrol --restart")
34
+ end
35
+
36
+ def self.reset
37
+ self.exec_sudo("sudo xcrun xcscontrol --reset")
38
+ end
39
+
40
+ def self.select(xcode)
41
+ self.exec_sudo("sudo xcode-select -s #{xcode}")
42
+ end
43
+
44
+ private
45
+
46
+ def self.exec_sudo(script)
47
+ XCSKarel.log.warn "Running \'#{script}\', so we need root privileges."
48
+ status, output = self.execute(script)
49
+ raise "Failed to \'#{script}\':\n#{output}".red if status != 0
50
+ XCSKarel.log.debug "Script \'#{script}\' output:\n#{output}"
51
+ return status, output
52
+ end
53
+
54
+ def self.execute(script)
55
+ exit_status = nil
56
+ result = []
57
+ IO.popen(script, err: [:child, :out]) do |io|
58
+ io.each do |line|
59
+ result << line.strip
60
+ end
61
+ io.close
62
+ exit_status = $?.exitstatus
63
+ end
64
+ [exit_status, result.join("\n")]
65
+ end
66
+ end
67
+ end
data/lib/karel/log.rb CHANGED
@@ -12,28 +12,25 @@ module XCSKarel
12
12
  def self.log
13
13
 
14
14
  @@log ||= Logger.new($stdout)
15
-
15
+ @@log.level = @@NO_LOG ? Logger::Severity::INFO : Logger::Severity::DEBUG
16
16
  @@log.formatter = proc do |severity, datetime, progname, msg|
17
17
 
18
- unless @@NO_LOG
19
- string = "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%2N')}]: "
20
- second = "#{msg}\n"
21
-
22
- if severity == "DEBUG"
23
- string = string.magenta
24
- elsif severity == "INFO"
25
- string = string.white
26
- elsif severity == "WARN"
27
- string = string.yellow
28
- elsif severity == "ERROR"
29
- string = string.red
30
- elsif severity == "FATAL"
31
- string = string.red.bold
32
- end
33
-
34
- [string, second].join("")
18
+ string = "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%2N')}]: "
19
+ second = "#{msg}\n"
20
+
21
+ if severity == "DEBUG"
22
+ string = string.magenta
23
+ elsif severity == "INFO"
24
+ string = string.white
25
+ elsif severity == "WARN"
26
+ string = string.yellow
27
+ elsif severity == "ERROR"
28
+ string = string.red
29
+ elsif severity == "FATAL"
30
+ string = string.red.bold
35
31
  end
36
-
32
+
33
+ [string, second].join("")
37
34
  end
38
35
  @@log
39
36
  end
data/lib/karel/server.rb CHANGED
@@ -80,10 +80,10 @@ module XCSKarel
80
80
  begin
81
81
  response = get_endpoint("/ping")
82
82
  rescue Exception => e
83
- raise "Failed to validate - #{e}.\nPlease make sure your Xcode Server is up and running at #{host}".red
83
+ raise "Failed to validate - #{e}.\nPlease make sure your Xcode Server is up and running at #{host}. Run `xcskarel server start` to start a new local Xcode Server instance.".red
84
84
  else
85
85
  raise "Failed to validate - Endpoint at \"#{url}\" responded with #{response.data[:status_line]}".red if response.status != 204
86
- XCSKarel.log.info "Validation of host #{@host} succeeded.".green
86
+ XCSKarel.log.debug "Validation of host #{@host} succeeded.".green
87
87
  end
88
88
  end
89
89
  end
data/lib/karel/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module XCSKarel
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3'
3
3
  end
data/lib/xcskarel.rb CHANGED
@@ -3,3 +3,4 @@ require 'karel/server'
3
3
  require 'karel/version'
4
4
  require 'karel/log'
5
5
  require 'karel/filter'
6
+ require 'karel/control'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcskarel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Honza Dvorsky
@@ -117,6 +117,7 @@ extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
119
  - bin/xcskarel
120
+ - lib/karel/control.rb
120
121
  - lib/karel/filter.rb
121
122
  - lib/karel/log.rb
122
123
  - lib/karel/server.rb