atk_toolbox 0.0.126 → 0.0.127

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57012bac4c7f283b708959f31767468a6462cdc03fe17ccedf389179e57ff554
4
- data.tar.gz: 525756a93ce1a7fc587e5fccccf1106d7b0d01815251edc943d90209291ca26c
3
+ metadata.gz: c9c4d780511982908f64d709071d17ccce1d7d7d7402aaec338fe28b4986c62c
4
+ data.tar.gz: 1574b3aa46422f14c5904b31cf095a10e4c426b8448f6864350f030c022080d2
5
5
  SHA512:
6
- metadata.gz: 80e4489665300858017f8ebd8bbcb45bfb47ba80b844db26999b1ad50822d014a81e34b596bf450537db0b7c8655034addf733d5e4600cdc2dc5c4b767d4ad85
7
- data.tar.gz: 1ef3e501ed87846015bb249ac16702b9d77e442553f246b67c468aaf2c4febe8440287d1cc394a20cdeaebdea741aa44ff628115ce3bef0d8a51cfc63ca4ab16
6
+ metadata.gz: a295b532b4bbc450e5f4d6e4b56734f3fbce52ae0662afa394647582a137346751f0eb1e19d93b58eb56bdf9fcb363f6d409ab41bf78fbf0aeac2ee45f1e828a
7
+ data.tar.gz: 222c45ef0e94b873adb9cc0bcd3a345f8b37c94d08374923b0a1606004d1ad1c3d5112020cce48a2af3bee304790d6e19dde00d47b16aa6b9f2603fe58a4cca5
data/lib/atk/atk_info.rb CHANGED
@@ -1,6 +1,6 @@
1
- require_relative './file_sys'
1
+ require_relative './file_system'
2
2
  require_relative './console'
3
- require_relative './yaml_info_parser'
3
+ require_relative './info'
4
4
  require_relative './os'
5
5
  require_relative './git'
6
6
  require 'yaml'
@@ -33,10 +33,16 @@ class AtkPaths
33
33
  end
34
34
  return ruby_path
35
35
  when 'gem'
36
- # TODO: this eventually needs to link to a specific version of ruby
36
+ # FUTURE: this should eventually link to a specific version of ruby instead of the global version
37
37
  return OS.path_for_executable("gem")
38
38
  when 'repos'
39
39
  return HOME/"atk"/"repos"
40
+ when 'commands'
41
+ if OS.is?("unix")
42
+ return "/usr/local/bin"
43
+ else
44
+ return "C:\\Users\\#{FS.username}\\AppData\\local\\Microsoft\\WindowsApps"
45
+ end
40
46
  end
41
47
  end
42
48
  end
@@ -93,6 +99,48 @@ module Atk
93
99
  FS.save(info_data, to: Atk.paths[:info], as: :yaml )
94
100
  end
95
101
 
102
+ def self.checkup
103
+ errors = {}
104
+
105
+ # make sure ruby is the corrct version
106
+ if VERSION_OF_RUBY >= Version.new("3.0.0")
107
+ errors[:ruby_version_too_high] = true
108
+ elsif VERSION_OF_RUBY < Version.new("2.5")
109
+ errors[:ruby_version_too_low] = true
110
+ end
111
+
112
+ # make sure git is installed and up to date
113
+ if not Console.has_command("git")
114
+ errors[:doesnt_have_git] = true
115
+ else
116
+ git_version = Version.extract_from(`git --version`)
117
+ if git_version < Version.new("2.17")
118
+ errors[:git_version_too_low] = true
119
+ end
120
+ end
121
+
122
+ # FUTURE: checkup on the package manager
123
+
124
+ # FUTURE: verify that windows and unix paths are highest priority
125
+
126
+ if OS.is?("unix")
127
+ sources = Console.command_sources()
128
+ top_source = sources[0]
129
+ path_for_commands = Atk.paths[:commands]
130
+ if top_source != path_for_commands
131
+ errors[:commands_are_not_at_top_of_path] = true
132
+ if not sources.any?{ |each| each == path_for_commands }
133
+ errors[:commands_are_not_in_path] = true
134
+ end
135
+ end
136
+ end
137
+
138
+ #
139
+ # TODO: talk about any found errors
140
+ #
141
+
142
+ end
143
+
96
144
  def self.setup(package_name, arguments)
97
145
  repo_url = AtkPackage.new(package_name).url
98
146
  project_folder = Atk.info["project_folder"]
@@ -100,7 +148,7 @@ module Atk
100
148
  if not project_folder
101
149
  # then use the current folder
102
150
  project_folder = FS.pwd
103
- puts "Project will be downloaded to #{project_folder.to_s.yellow}"
151
+ puts "Project will be downloaded to #{project_folder.to_s.color_as :key_term}"
104
152
  puts "(your current directory)"
105
153
  puts ""
106
154
  end
@@ -110,7 +158,7 @@ module Atk
110
158
  FS.in_dir(project_path) do
111
159
  setup_command = Info.commands['(setup)']
112
160
  if setup_command.is_a?(Code) || setup_command.is_a?(String)
113
- puts "\n\nRunning (setup) command:\n".green
161
+ puts "\n\n#{"Running (setup) command:".color_as :title}\n"
114
162
  sleep 1
115
163
  if setup_command.is_a?(Code)
116
164
  setup_command.run(arguments)
@@ -119,10 +167,10 @@ module Atk
119
167
  end
120
168
  end
121
169
  puts "\n\n\n\n============================================================"
122
- puts "Finished running setup for: #{project_path.green}"
170
+ puts "Finished running setup for: #{project_path.color_as :good}"
123
171
  puts "This project has these commands avalible:"
124
172
  system "project commands"
125
- puts "\ndon't forget to do:\n#{"cd '#{project_path}'".blue}"
173
+ puts "\ndon't forget to do:\n#{"cd '#{project_path}'".color_as :code}"
126
174
  end
127
175
  end
128
176
 
@@ -135,16 +183,43 @@ module Atk
135
183
  puts "Sorry, this feature is still under development"
136
184
  end
137
185
 
138
- def self.update()
139
- system(Atk.paths['gem'], 'install', "atk_toolbox")
186
+ def self.update(*args)
187
+ #
188
+ # update a specific repo/package
189
+ #
190
+ if args.size != 0
191
+ Atk.not_yet_implemented()
192
+ return
193
+ end
194
+
195
+ #
196
+ # update ATK itself
197
+ #
198
+ puts "Checking latest online version"
199
+ console_output = IO.popen([Atk.paths['gem'], "list", "atk_toolbox", "--remote"]).read
200
+ filtered = console_output.split("\n").select{|each| each =~ /^atk_toolbox \(/}
201
+ latest_version = Version.extract_from(filtered[0])
202
+ # if update avalible
203
+ if Atk.version < latest_version
204
+ puts "Newer version avalible, installing now"
205
+ # install the new gem
206
+ system(Atk.paths['gem'], "install", "atk_toolbox")
207
+ # run the update handler
208
+ temp_file = Atk.temp_path("after_gem_update.rb")
209
+ FS.download("https://raw.githubusercontent.com/aggie-tool-kit/atk-toolbox/master/lib/after_gem_update.rb", to: temp_file)
210
+ system(Atk.paths["ruby"], temp_file, Atk.version.to_s)
211
+ else
212
+ puts "System up to date"
213
+ end
140
214
  end
141
215
  end
142
216
  ATK = Atk
143
217
 
144
-
145
218
  class AtkPackage
146
219
  def initialize(package_name)
147
220
  @init_name = package_name
221
+ @package_info_loaded = false
222
+ @dont_exist = {}
148
223
  end
149
224
 
150
225
  def simple_name
@@ -200,63 +275,158 @@ class AtkPackage
200
275
  end
201
276
  end
202
277
 
203
- def run(arguments)
204
- # make sure the repo is downloaded
205
- self.ensure_cached()
206
- FS.in_dir(self.cache_location) do
207
- run_command = nil
208
- begin
209
- run_command = Info["(installer)"]["(commands)"]["(run)"]
210
- rescue
211
- end
212
- if run_command.is_a?(String)
213
- system(run_command + Console.make_arguments_appendable(arguments))
214
- else
215
- #
216
- # refine the error message
217
- #
218
- custom_message = ""
219
- if run_command != nil && ( !run_command.is_a?(String) )
220
- custom_message = "✖ the (run) command wasn't a string".red
221
- else
222
- yaml_exists = File.exist?(self.cache_location()/"info.yaml")
223
-
224
- if not yaml_exists
225
- custom_message = "✖ there was no info.yaml for this package".red
278
+ #
279
+ # parse package
280
+ #
281
+ def ensure_package_info()
282
+ if not @package_info_loaded
283
+ @package_info_loaded = true
284
+ self.ensure_cached()
285
+ FS.in_dir(self.cache_location) do
286
+ if not FS.file?("./info.yaml")
287
+ @dont_exist[:yaml_file] = true
288
+ end
289
+ begin
290
+ # must be in top most dir
291
+ @info = YAML.load_file("./info.yaml")
292
+ rescue => exception
293
+ @dont_exist[:correctly_formatted_yaml_file] = true
294
+ end
295
+
296
+ # attempt to load a version
297
+ begin
298
+ version = Version.new(@info['(using_atk_version)'])
299
+ rescue => exception
300
+ version = nil
301
+ @dont_exist[:using_atk_version] = true
302
+ end
303
+ # if there is a version
304
+ if version.is_a?(Version)
305
+ # if the version is really old
306
+ if version <= Version.new("1.0.0")
307
+ raise <<-HEREDOC.remove_indent
308
+
309
+
310
+ It appears that the #{self.simple_name()} package is using
311
+ the alpha version of ATK (1.0.0), which is no longer supported.
312
+ This is probably just a simple versioning mistake.
313
+ Please ask the maintainer of the #{self.simple_name()} package to
314
+ update it to a newer ATK package format
315
+ HEREDOC
316
+ elsif version <= Version.new("1.1.0")
317
+ self.parser_version_1_1(@info)
226
318
  else
227
- error_loading_yaml = false
228
- begin
229
- YAML.load_file("./info.yaml")
230
- rescue
231
- error_loading_yaml = true
232
- end
233
- if error_loading_yaml
234
- custom_message = "✖ there was an issue loading the info.yaml for this package".red
235
- else
236
- if run_command == nil
237
- custom_message = "✖ there wasn't an (installer) key with a run command".red
238
- end
239
- end
240
- end
319
+ raise <<-HEREDOC.remove_indent
320
+
321
+
322
+ The package #{self.simple_name()} has a (using_atk_version)
323
+ that is newer than the currently installed ATK can handle:
324
+ version: #{version}
325
+
326
+ This means either
327
+ 1. ATK needs to be updated (which you can do with #{'atk update'.color_as :code})
328
+ 2. The package has specified a version of ATK that doesn't exist
329
+ HEREDOC
330
+ end
241
331
  end
332
+ end
333
+ end
334
+ end
335
+
336
+ #
337
+ # (using_atk_version) 1.1.0
338
+ #
339
+ # (package):
340
+ # (actions):
341
+ # (run): *run command as string*
342
+ def parser_version_1_1(info)
343
+ #
344
+ # inits:
345
+ # @package_info: nil
346
+ # @actions: {}
347
+ # @run: nil
348
+ #
349
+ if @info.is_a?(Hash)
350
+ @package_info = @info['(package)']
351
+ if @package_info.is_a?(Hash)
352
+ @actions = @package_info['(actions)']
353
+ else
354
+ @dont_exist[:package_info] = true
355
+ end
356
+ if not @actions.is_a?(Hash)
357
+ @actions = {}
358
+ @dont_exist[:actions] = true
359
+ end
360
+
361
+ @run = @actions['(run)']
362
+ if not @run.is_a?(String)
363
+ @dont_exist[:run_action] = true
364
+ end
365
+ end
366
+ end
367
+
368
+ def run(arguments)
369
+ self.ensure_package_info()
370
+ # if it exists, run it
371
+ if @run.is_a?(String)
372
+ FS.in_dir(self.cache_location) do
373
+ system(@run + Console.make_arguments_appendable(arguments))
374
+ return $?.success?
375
+ end
376
+ # if not, explain why not
377
+ else
378
+ custom_message = <<-HEREDOC.remove_indent
379
+
380
+ When trying
381
+ to perform the #{"run".color_as :code} action
382
+ on the #{self.simple_name.to_s.color_as :key_term} module
383
+ with these arguments: #{arguments.inspect.to_s.color_as :argument}
242
384
 
243
- # throw error for command not being runable
244
- raise <<-HEREDOC.remove_indent
245
-
385
+ There was an issue because:
386
+ HEREDOC
387
+
388
+ # FUTURE: make a more standardized error reporting tool and it that here
389
+
390
+ good = ->(message) do
391
+ " ✓ #{message.color_as :good}"
392
+ end
393
+ bad = ->(message) do
394
+ " ✖ #{message.color_as :bad}"
395
+ end
396
+
397
+ if @dont_exist[:yaml_file]
398
+ custom_message += <<-HEREDOC.remove_indent
399
+ #{bad("there was no info.yaml for that package")}
400
+ and an info.yaml is the location for defining a run action
246
401
 
247
- #{custom_message}
402
+ HEREDOC
403
+ elsif @dont_exist[:correctly_formatted_yaml_file]
404
+ custom_message += <<-HEREDOC.remove_indent
405
+ #{good("there was a info.yaml for that package")}
406
+ #{bad("the info.yaml is not parseable")}
407
+ and an info.yaml is the location for defining a run action
248
408
 
249
- For the repository to be runnable
250
- 1. There needs to be an #{"info.yaml".blue}
251
- 2. The info.yaml needs to be in the root directory/folder
252
- 3. It needs to contain:
253
- #{"
254
- (installer):
255
- (commands):
256
- (run): \"a commandline command\"
257
- ".blue}
409
+ HEREDOC
410
+ elsif @dont_exist[:using_atk_version]
411
+ custom_message += <<-HEREDOC.remove_indent
412
+ #{good("there was a info.yaml for that package")}
413
+ #{good("the info.yaml was parseable")}
414
+ #{@dont_exist[:using_atk_version] && bad("the info.yaml didn't have a (using_atk_version) key")}
415
+ #{@dont_exist[:package_info] && bad("the info.yaml didn't have a (package_info) key")}
416
+ #{@dont_exist[:actions] && bad("the info.yaml didn't have a (package_info): (actions) key")}
417
+ #{@dont_exist[:run_action] && bad("the info.yaml didn't have a (package_info): (actions): (run) key")}
258
418
  HEREDOC
259
419
  end
420
+
421
+ raise <<-HEREDOC.remove_indent
422
+
423
+
424
+ #{custom_message}
425
+
426
+ This is almost certainly a problem with the package
427
+ Please contact the maintainer of #{self.simple_name}
428
+ and let them know about the above issue
429
+ HEREDOC
260
430
  end
261
431
  end
262
432
  end
@@ -1,7 +1,7 @@
1
1
  module Atk
2
2
  def self.autocomplete(which_command)
3
3
  if which_command == '_'
4
- require_relative './yaml_info_parser.rb'
4
+ require_relative './info.rb'
5
5
  begin
6
6
  puts Info.commands().keys.map { |each| each.gsub(' ', '\ ') }.join(' ')
7
7
  rescue => exception
@@ -2,70 +2,91 @@ require_relative '../atk_info'
2
2
 
3
3
  module Atk
4
4
  def self.project(args)
5
- # TODO: check to make sure project exists
5
+ #
6
+ # no arguments
7
+ #
6
8
  if args.length == 0
7
- puts "if you don't know how to use #{"project".blue} just run #{"project help".blue}"
9
+ begin
10
+ info = Info.new
11
+ rescue Info::YamlFileDoesntExist => exception
12
+ puts <<-HEREDOC.remove_indent
13
+
14
+ It appears there is no #{"info.yaml".color_as :code} file
15
+ Meaning you're probably not in folder that contains a project
16
+
17
+ To convert the current folder into a project folder run:
18
+ #{"project init".color_as :code}
19
+
20
+ If you don't know how to use #{"project".color_as :code} just run #{"project help".color_as :code}
21
+ HEREDOC
22
+ exit
23
+ end
24
+ puts "If you don't know how to use #{"project".color_as :code} just run #{"project help".color_as :code}"
8
25
  puts ""
9
26
  # if there are commands then show them
10
- commands = Info.commands
27
+ commands = info.commands
11
28
  if commands.is_a?(Hash) && commands.keys.size > 0
12
29
  puts "commands for current project:"
13
30
  puts `project commands`
14
31
  end
15
32
  else
16
- #
17
- # Check dependencies
18
- #
19
- # if they're not met, then warn the user about that
20
- # check a hash of the file to see if anything has changed
21
33
  case args[0]
34
+ #
35
+ # help
36
+ #
22
37
  when 'help', '--help', '-h'
23
38
  puts <<-HEREDOC.remove_indent
24
- #{"help".yellow}
25
- #{"info:".green} displays the avalible tools
26
- #{"examples:".green} #{'project help'.blue}
39
+ #{"help".color_as :key_term}
40
+ #{"info:".color_as :title} displays the avalible tools
41
+ #{"examples:".color_as :title} #{'project help'.color_as :code}
27
42
 
28
- #{"initialize".yellow}
29
- #{"examples:".green}
30
- #{'project init'.blue}
31
- #{'project initialize'.blue}
32
- #{"info:".green}
43
+ #{"initialize".color_as :key_term}
44
+ #{"examples:".color_as :title}
45
+ #{'project init'.color_as :code}
46
+ #{'project initialize'.color_as :code}
47
+ #{"info:".color_as :title}
33
48
  This will create an info.yaml in your current directory
34
49
  The info.yaml will contain all the standard project managment tools
35
50
  In the future this command will be more interactive
36
51
 
37
- #{"synchronize".yellow}
38
- #{"examples:".green}
39
- #{'project sync'.blue}
40
- #{'project synchronize'.blue}
41
- #{'project synchronize --message=\'updated the readme\''.blue}
42
- #{"info:".green}
52
+ #{"synchronize".color_as :key_term}
53
+ #{"examples:".color_as :title}
54
+ #{'project sync'.color_as :code}
55
+ #{'project synchronize'.color_as :code}
56
+ #{'project synchronize --message=\'updated the readme\''.color_as :code}
57
+ #{"info:".color_as :title}
43
58
  Adds, commits, and then pulls/pushes all git changes
44
59
  If there is merge conflict, it will show up as normal
45
- #{"format:".green}
46
- #{"project".blue} #{"synchronize".yellow} #{"<package>".cyan} #{"--message='your message'".light_magenta}
60
+ #{"format:".color_as :title}
61
+ #{"project".color_as :code} #{"synchronize".color_as :key_term} #{"<package>".color_as :argument} #{"--message='your message'".color_as :optional}
47
62
 
48
- #{"execute".yellow}
49
- #{"examples:".green}
50
- #{'project execute compile'.blue}
51
- #{'project exec compile'.blue}
52
- #{'project exec main'.blue}
53
- #{'project exec server'.blue}
54
- #{"info:".green}
63
+ #{"execute".color_as :key_term}
64
+ #{"examples:".color_as :title}
65
+ #{'project execute compile'.color_as :code}
66
+ #{'project exec compile'.color_as :code}
67
+ #{'project exec main'.color_as :code}
68
+ #{'project exec server'.color_as :code}
69
+ #{"info:".color_as :title}
55
70
  This will look at the info.yaml file in your project to find commands
56
71
  You can use the `project init` command to generate an info.yaml which
57
72
  has example commands. Commands can be CMD/terminal/console commands, or ruby code.
58
- #{"format:".green}
59
- #{"project".blue} #{"execute".yellow} #{"<name-of-command>".cyan} #{"<arg1-for-command>".light_magenta} #{"<arg2-for-command>".light_magenta} #{"<...etc>".light_magenta}
73
+ #{"format:".color_as :title}
74
+ #{"project".color_as :code} #{"execute".color_as :key_term} #{"<name-of-command>".color_as :argument} #{"<arg1-for-command>".color_as :optional} #{"<arg2-for-command>".color_as :optional} #{"<...etc>".color_as :optional}
60
75
 
61
- #{"commands".yellow}
62
- #{"examples:".green} #{'project commands'.blue}
63
- #{"info:".green}
76
+ #{"commands".color_as :key_term}
77
+ #{"examples:".color_as :title} #{'project commands'.color_as :code}
78
+ #{"info:".color_as :title}
64
79
  This will read the local info.yaml of your project to find commands
65
80
  then it will list out each command with a short preview of the contents of that command
66
81
  HEREDOC
82
+ #
83
+ # init
84
+ #
67
85
  when 'initialize', 'init'
68
86
  Info.init
87
+ #
88
+ # sync
89
+ #
69
90
  when 'synchronize', 'sync'
70
91
  # if there is an argument
71
92
  git_folder_path = FS.dirname(Info.path)/".git"
@@ -103,35 +124,13 @@ module Atk
103
124
  system('git pull --no-edit')
104
125
  # push up everything
105
126
  system('git push')
106
-
107
- when 'mix'
108
- not_yet_implemented()
109
- structure_name = args[1]
110
- # use this to mix a structure into the project
111
- # TODO:
112
- # get the context
113
- # if there is a --context='something' command line option, then use that
114
- # otherwise use the default(--context) speficied in the info.yaml
115
- # re-iterate through the info.yaml (advanced_setup) keys
116
- # find all of the "when(--context = 'something')" keys
117
- # find the (dependencies) sub-key for them, create one if the key doesn't exist
118
- # add the project and version to the
119
- when 'add'
120
- not_yet_implemented()
121
- package = args[1]
122
- # check if there is an info.yaml
123
- # check if there is an local_package_manager in the info.yaml
124
- # if there is only 1, then use it
125
- # if there is more than one, ask which one the user wants to use
126
- when 'remove'
127
- not_yet_implemented()
128
- package = args[1]
129
- # check if there is an local_package_manager in the info.yaml
130
- # if it does use it to remove the package
127
+ #
128
+ # execute
129
+ #
131
130
  when 'execute', 'exec'
132
131
  # extract the (project_commands) section from the info.yaml,
133
132
  # then find the command with the same name as args[1] and run it
134
- # TODO: use https://github.com/piotrmurach/tty-markdown#ttymarkdown- to highlight the ruby code
133
+ # FUTURE: use https://github.com/piotrmurach/tty-markdown#ttymarkdown- to highlight the ruby code
135
134
  _, command_name, *command_args = args
136
135
  command = Info.commands[command_name]
137
136
  # temporairly set the dir to be the same as the info.yaml
@@ -144,16 +143,22 @@ module Atk
144
143
  puts "I don't think that command is in the info.yaml file"
145
144
  end
146
145
  end
146
+ #
147
+ # commands
148
+ #
147
149
  when 'commands'
148
150
  max_number_of_chars_to_show = 80
149
151
  commands = Info.commands
150
152
  if commands.keys.size == 0
151
- puts "0 avalible commands".cyan
153
+ puts "0 avalible commands".color_as :message
152
154
  else
153
155
  for each_key, each_value in commands
154
- puts " #{each_key.to_s.yellow}: #{each_value.to_s.strip[0..max_number_of_chars_to_show].sub(/(.*)[\s\S]*/,'\1')}"
156
+ puts " #{each_key.to_s.color_as :key_term}: #{each_value.to_s.strip[0..max_number_of_chars_to_show].sub(/(.*)[\s\S]*/,'\1')}"
155
157
  end
156
158
  end
159
+ #
160
+ # unrecognized
161
+ #
157
162
  else
158
163
  puts "I don't recognized that command\nhere's the `project --help` which might get you what you're looking for:"
159
164
  Atk.project(["help"])