atk_toolbox 0.0.108 → 0.0.109

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: 5411f6c02f2858c7b8eaacb44b70f64ad2c9d685834f7f698be18ca32b034dbf
4
- data.tar.gz: 04be1ee289fd1f0251fa4b885adc997f31d7fc1d799fbea423d7c9b661072459
3
+ metadata.gz: cb7564990fc348d432e32a8657f4311049b88460b607cb928371d629a6c05a5a
4
+ data.tar.gz: cc9f1798043595bac786b73b14d219944f2a82fe1524f834dbb0af9401f21d3c
5
5
  SHA512:
6
- metadata.gz: d3965debfbace8fef01c8940aa672f3207116357d5f6ec9c8a349e17b866b6aa7665b20968fbf22e3fc7893821243bede06f24e5f72e8e94f4063343fab9598a
7
- data.tar.gz: 12181aed8b01e777dc4e2baeb7f8ad5bb61edce4b08adb937be23fd7a0d101f8a4bad239b0da75e78a2d64e300952c6f186270e59b93a51917f7432bd4038ef1
6
+ metadata.gz: c948f809e4e2b229d7aa6e122f9001e4554c8ec6fb6dbc2feb798dff3d0c88e25e9df13bf363f2249feb27515b4527ccc76e738ac2c975ddb9e955d211cd2b3a
7
+ data.tar.gz: ac8c6d6c24a1540ab1a5867c8a1c5ac5dd5d90741e4eb0367fef828fbf96df5f83d67021712b5aa7452e2d54fdeed5bb152a3e5d6964c43a65d8ee12e2801335
@@ -0,0 +1,12 @@
1
+ module Atk
2
+ def self.autocomplete(which_command)
3
+ if which_command == '_'
4
+ require_relative './yaml_info_parser.rb'
5
+ begin
6
+ puts Info.project_commands().keys.map { |each| each.gsub(' ', '\ ') }.join(' ')
7
+ rescue => exception
8
+ puts ""
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,4 +1,3 @@
1
- require_relative './os'
2
1
  require_relative './remove_indent'
3
2
  require_relative './version'
4
3
  require 'json'
@@ -145,11 +144,4 @@ class Psych::Nodes::Node
145
144
  new_string = inject_string(@document.string, middle_part, @start_line, @start_column, @end_line, @end_column)
146
145
  @document.init( string: new_string )
147
146
  end
148
- end
149
-
150
-
151
- class String
152
- def yaml
153
- return YAML.load(self)
154
- end
155
- end
147
+ end
data/lib/atk/file_sys.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  require 'etc'
2
2
  require 'fileutils'
3
3
  require 'pathname'
4
- require 'open-uri'
5
- require 'json'
6
- require 'yaml'
7
- require 'csv'
8
4
  require_relative './os'
9
5
  require_relative './remove_indent'
10
6
 
@@ -29,7 +25,7 @@ class String
29
25
  end
30
26
  end
31
27
 
32
- module FileSys
28
+ module FileSystem
33
29
  # This is a combination of the FileUtils, File, Pathname, IO, Etc, and Dir classes,
34
30
  # along with some other helpful methods
35
31
  # It is by-default forceful (dangerous/overwriting)
@@ -44,7 +40,7 @@ module FileSys
44
40
 
45
41
  def self.write(data, to:nil)
46
42
  # make sure the containing folder exists
47
- FileSys.makedirs(File.dirname(to))
43
+ FileSystem.makedirs(File.dirname(to))
48
44
  # actually download the file
49
45
  IO.write(to, data)
50
46
  end
@@ -58,8 +54,11 @@ module FileSys
58
54
  # add a special exception for csv files
59
55
  case as
60
56
  when :csv
57
+ require 'csv'
61
58
  FS.write(value.map(&:to_csv).join, to: to)
62
59
  else
60
+ require 'json'
61
+ require 'yaml'
63
62
  conversion_method_name = "to_#{as}"
64
63
  if value.respond_to? conversion_method_name
65
64
  # this is like calling `value.to_json`, `value.to_yaml`, or `value.to_csv` but programatically
@@ -68,12 +67,12 @@ module FileSys
68
67
  raise <<-HEREDOC.remove_indent
69
68
 
70
69
 
71
- The FileSys.save(value, to: #{to.inspect}, as: #{as.inspect}) had a problem.
70
+ The FileSystem.save(value, to: #{to.inspect}, as: #{as.inspect}) had a problem.
72
71
  The as: #{as}, gets converted into value.to_#{as}
73
72
  Normally that returns a string that can be saved to a file
74
73
  However, the value.to_#{as} did not return a string.
75
74
  Value is of the #{value.class} class. Add a `to_#{as}`
76
- method to that class that returns a string to get FileSys.save() working
75
+ method to that class that returns a string to get FileSystem.save() working
77
76
  HEREDOC
78
77
  end
79
78
  FS.write(string_value, to:to)
@@ -81,13 +80,13 @@ module FileSys
81
80
  raise <<-HEREDOC.remove_indent
82
81
 
83
82
 
84
- The FileSys.save(value, to: #{to.inspect}, as: #{as.inspect}) had a problem.
83
+ The FileSystem.save(value, to: #{to.inspect}, as: #{as.inspect}) had a problem.
85
84
 
86
85
  The as: #{as}, gets converted into value.to_#{as}
87
86
  Normally that returns a string that can be saved to a file
88
87
  However, the value.to_#{as} is not a method for value
89
88
  Value is of the #{value.class} class. Add a `to_#{as}`
90
- method to that class that returns a string to get FileSys.save() working
89
+ method to that class that returns a string to get FileSystem.save() working
91
90
  HEREDOC
92
91
  end
93
92
  end
@@ -135,24 +134,24 @@ module FileSys
135
134
 
136
135
  def self.copy(from:nil, to:nil, new_name:"", force: true, preserve: false, dereference_root: false)
137
136
  if new_name == ""
138
- raise "\n\nFileSys.copy() needs a new_name: argument\nset new_name:nil if you wish the file/folder to keep the same name\ne.g. FileSys.copy(from:'place/thing', to:'place', new_name:nil)"
137
+ raise "\n\nFileSystem.copy() needs a new_name: argument\nset new_name:nil if you wish the file/folder to keep the same name\ne.g. FileSystem.copy(from:'place/thing', to:'place', new_name:nil)"
139
138
  elsif new_name == nil
140
139
  new_name = File.basename(from)
141
140
  end
142
141
  # make sure the "to" path exists
143
- FileSys.touch_dir(to)
142
+ FileSystem.touch_dir(to)
144
143
  # perform the copy
145
144
  FileUtils.copy_entry(from, to/new_name, preserve, dereference_root, force)
146
145
  end
147
146
 
148
147
  def self.move(from:nil, to:nil, new_name:"", force: true, noop: nil, verbose: nil, secure: nil)
149
148
  if new_name == ""
150
- raise "\n\nFileSys.move() needs a new_name: argument\nset new_name:nil if you wish the file/folder to keep the same name\ne.g. FileSys.move(from:'place/thing', to:'place', new_name:nil)"
149
+ raise "\n\nFileSystem.move() needs a new_name: argument\nset new_name:nil if you wish the file/folder to keep the same name\ne.g. FileSystem.move(from:'place/thing', to:'place', new_name:nil)"
151
150
  elsif new_name == nil
152
151
  new_name = File.basename(from)
153
152
  end
154
153
  # make sure the "to" path exists
155
- FileSys.touch_dir(to)
154
+ FileSystem.touch_dir(to)
156
155
  # perform the move
157
156
  FileUtils.move(from, to/new_name, force: force, noop: noop, verbose: verbose, secure: secure)
158
157
  end
@@ -160,11 +159,11 @@ module FileSys
160
159
  def self.rename(from:nil, to:nil, force: true)
161
160
  # if the directories are different, then throw an error
162
161
  if not File.identical?(File.dirname(from), File.dirname(to))
163
- raise "\n\nFileSys.rename() requires that the the file stay in the same place and only change names.\nIf you want to move a file, use FileSys.move()"
162
+ raise "\n\nFileSystem.rename() requires that the the file stay in the same place and only change names.\nIf you want to move a file, use FileSystem.move()"
164
163
  end
165
164
  # make sure the path is clear
166
165
  if force
167
- FileSys.delete(to)
166
+ FileSystem.delete(to)
168
167
  end
169
168
  # perform the copy
170
169
  File.rename(from, to)
@@ -177,7 +176,7 @@ module FileSys
177
176
  singleton_class.send(:alias_method, :new_file, :touch)
178
177
 
179
178
  def self.touch_dir(path)
180
- if not FileSys.directory?(path)
179
+ if not FileSystem.directory?(path)
181
180
  FileUtils.makedirs(path)
182
181
  end
183
182
  end
@@ -205,7 +204,7 @@ module FileSys
205
204
  extname = File.extname(pieces[-1])
206
205
  basebasename = pieces[-1][0...(pieces[-1].size - extname.size)]
207
206
  # add the root if the path is absolute
208
- if FileSys.abs?(path)
207
+ if FileSystem.abs?(path)
209
208
  if not OS.is?("windows")
210
209
  pieces.unshift('/')
211
210
  else
@@ -224,10 +223,10 @@ module FileSys
224
223
  Dir.glob(path, File::FNM_DOTMATCH) - %w[. ..]
225
224
  end
226
225
  def self.list_files(path=".")
227
- Dir.children(path).map{|each| path/each }.select {|each| FileSys.file?(each)}
226
+ Dir.children(path).map{|each| path/each }.select {|each| FileSystem.file?(each)}
228
227
  end
229
228
  def self.list_folders(path=".")
230
- Dir.children(path).map{|each| path/each }.select {|each| FileSys.directory?(each)}
229
+ Dir.children(path).map{|each| path/each }.select {|each| FileSystem.directory?(each)}
231
230
  end
232
231
  def self.ls(path=".")
233
232
  Dir.children(path)
@@ -379,6 +378,7 @@ module FileSys
379
378
  end
380
379
 
381
380
  def self.download(input=nil, from:nil, url:nil, to:nil)
381
+ require 'open-uri'
382
382
  # if only one argument, either input or url
383
383
  if ((input!=nil) != (url!=nil)) && (from==nil) && (to==nil)
384
384
  # this covers:
@@ -409,8 +409,8 @@ module FileSys
409
409
  download 'file', url:'site.com/file'
410
410
  HEREDOC
411
411
  end
412
- FileSys.write(open(URI.encode(the_url)).read, to: file_name)
412
+ FileSystem.write(open(URI.encode(the_url)).read, to: file_name)
413
413
  end
414
414
  end
415
- # create an FS singleton_class.send(:alias_method, :FS = :FileSys)
416
- FS = FileSys
415
+ # create an FS singleton_class.send(:alias_method, :FS = :FileSystem)
416
+ FS = FileSystem
data/lib/atk/os.rb CHANGED
@@ -1,47 +1,4 @@
1
1
  require_relative './version.rb'
2
- # every OS version is a perfect heirarchy of versions and sub verisons that may or may not be chronological
3
- # every OS gets it's own custom heirarchy since there are issues like x86 support and "student edition" etc
4
- # the plan is to release this heirarchy on its own repo, and to get pull requests for anyone who wants to add their own OS
5
- os_heirarchy = {
6
- "windows" => {
7
- "10" => {},
8
- "8.1" => {},
9
- "8" => {},
10
- "7" => {},
11
- "vista" => {},
12
- "xp" => {},
13
- "95" => {},
14
- },
15
- "mac" => {
16
- "mojave" => {},
17
- "high sierra" => {},
18
- "sierra" => {},
19
- "el capitan" => {},
20
- "yosemite" => {},
21
- "mavericks" => {},
22
- "mountain lion" => {},
23
- "lion" => {},
24
- "snow leopard" => {},
25
- "leopard" => {},
26
- "tiger" => {},
27
- "panther" => {},
28
- "jaguar" => {},
29
- "puma" => {},
30
- "cheetah" => {},
31
- "kodiak" => {},
32
- },
33
- "ubuntu" => {},
34
- "arch" => {},
35
- "manjaro" => {},
36
- "deepin" => {},
37
- "centos" => {},
38
- "debian" => {},
39
- "fedora" => {},
40
- "elementary" => {},
41
- "zorin" => {},
42
- "raspian" => {},
43
- "android" => {},
44
- }
45
2
 
46
3
  # this statment was extracted from the ptools gem, credit should go to them
47
4
  # https://github.com/djberg96/ptools/blob/master/lib/ptools.rb
@@ -1,11 +1,27 @@
1
1
  require "yaml"
2
- require_relative './console'
2
+ require "colorize"
3
3
  require_relative './os'
4
- require_relative './file_sys'
5
- require_relative './extra_yaml'
6
4
  require 'fileutils'
7
5
  require_relative './remove_indent.rb'
8
6
 
7
+ # duplicated for the sake of efficieny (so that the parser doesn't need to import all of FileSystem)
8
+ module FileSystem
9
+ def self.join(*args)
10
+ if OS.is?("windows")
11
+ folders_without_leading_or_trailing_slashes = args.map do |each|
12
+ # replace all forward slashes with backslashes
13
+ backslashed_only = each.gsub(/\//,"\\")
14
+ # remove leading/trailing backslashes
15
+ backslashed_only.gsub(/(^\\|^\/|\\$|\/$)/,"")
16
+ end
17
+ # join all of them with backslashes
18
+ folders_without_leading_or_trailing_slashes.join("\\")
19
+ else
20
+ File.join(*args)
21
+ end
22
+ end
23
+ end
24
+
9
25
  # TODO: for efficiency, have the parser generate a parsed object, instead of only handling everything dynamically (allow for both)
10
26
 
11
27
  #
@@ -103,7 +119,7 @@ class Info
103
119
  def self.init
104
120
  current_dir = Dir.pwd/"info.yaml"
105
121
  # if there isn't a info.yaml then create one
106
- if not FS.file?(current_dir)
122
+ if not File.file?(current_dir)
107
123
  # copy the default yaml to the current dir
108
124
  FileUtils.cp(__dir__/"default_info.yaml", current_dir)
109
125
  puts "info.yaml created successfully"
@@ -225,25 +241,27 @@ class Info
225
241
  # @@environment_variables
226
242
 
227
243
  # get the local yaml file
228
- if FS.file?(Info.source_path)
229
- begin
230
- @@data = YAML.load_file(Info.source_path)
231
- if @@data['(using_atk_version)'] != 1.0
232
- raise <<-HEREDOC.remove_indent
233
-
234
-
235
- When opening the info.yaml file in '#{self.folder}'
236
- the (using_atk_version) was listed as: #{@@data['(using_atk_version)'].inspect}
237
- The version of atk_toolbox you have installed is only capable of handling version 1.0
238
- either atk_toolbox needs to be changed, or the (using_atk_version) version needs to be changed.
239
- HEREDOC
240
- end
241
- rescue => exception
244
+ absolute_parent_path = File.absolute_path(Info.folder())
245
+ source = FileSystem.join(absolute_parent_path, "info.yaml")
246
+ begin
247
+ @@data = YAML.load_file(source)
248
+ if @@data['(using_atk_version)'] != 1.0
249
+ raise <<-HEREDOC.remove_indent
250
+
251
+
252
+ When opening the info.yaml file in '#{self.folder}'
253
+ the (using_atk_version) was listed as: #{@@data['(using_atk_version)'].inspect}
254
+ The version of atk_toolbox you have installed is only capable of handling version 1.0
255
+ either atk_toolbox needs to be changed, or the (using_atk_version) version needs to be changed.
256
+ HEREDOC
257
+ end
258
+ rescue
259
+ if File.file?(source)
242
260
  puts "\n\nI'm having trouble loading the info.yaml file. Here's the error:\n".red
243
261
  raise exception
262
+ else
263
+ raise "\n\nCouldn't find an info.yaml file in #{Dir.pwd}".red
244
264
  end
245
- else
246
- raise "\n\nCouldn't find an info.yaml file in #{Dir.pwd}".red
247
265
  end
248
266
  @@project = @@data['(project)']
249
267
  if @@project == nil
@@ -269,7 +287,7 @@ class Info
269
287
  for each_key, each_value in @@paths
270
288
  # if its an array, just join it together
271
289
  if each_value.is_a?(Array)
272
- each_value = FS.join(*each_value)
290
+ each_value = FileSystem.join(*each_value)
273
291
  end
274
292
  if each_value.is_a?(String)
275
293
  # remove the ./ if it exists
@@ -279,7 +297,7 @@ class Info
279
297
  # Dont add a source_path if its an absolute path
280
298
  if not each_value.size > 0 && each_value[0] == '/'
281
299
  # convert the path into an absolute path
282
- @@paths[each_key] = FS.absolute_path(FS.dirname(Info.source_path)) / each_value
300
+ @@paths[each_key] = FileSystem.join(absolute_parent_path , each_value)
283
301
  end
284
302
  end
285
303
  end
@@ -304,29 +322,30 @@ class Info
304
322
  end
305
323
 
306
324
  def self.folder()
307
- first_location = Dir.pwd/"info.yaml"
308
- *folders, name, ext = FS.path_pieces(first_location)
325
+ folder = Dir.pwd
309
326
  loop do
327
+ # if the info.yaml exists in that folder
328
+ if FileSystem.join(folder, "info.yaml")
329
+ return folder
330
+ end
331
+
332
+ next_location = File.dirname(folder)
333
+
310
334
  # if all folders exhausted
311
- if folders.size == 0
335
+ if next_location == folder
312
336
  raise <<-HEREDOC.remove_indent.red
313
337
 
314
- Couldn't find an info.yaml in the current directory or any parent directory
338
+ #{"Couldn't find an info.yaml in the current directory or any parent directory".red}
315
339
  #{Dir.pwd}
316
340
  Are you sure you're running the command from the correct directory?
317
341
  HEREDOC
318
342
  end
319
- # if the info.yaml exists, then use it
320
- path = FS.join(*folders, "info.yaml")
321
- if FS.file?(path)
322
- return FS.join(*folders)
323
- end
324
- # go up the folders
325
- folders.pop()
343
+
344
+ folder = next_location
326
345
  end
327
346
  end
328
347
 
329
348
  def self.source_path()
330
- return self.folder()/"info.yaml"
349
+ return FileSystem.join( self.folder(), "info.yaml")
331
350
  end
332
351
  end
@@ -1,3 +1,3 @@
1
1
  module AtkToolbox
2
- VERSION = '0.0.108'
2
+ VERSION = '0.0.109'
3
3
  end
data/test/main.rb CHANGED
@@ -2,4 +2,7 @@ require_relative '../lib/atk_toolbox'
2
2
 
3
3
  Dir.chdir __dir__
4
4
 
5
- puts Info.paths.to_yaml
5
+ puts Info.paths.to_yaml
6
+
7
+ # only require the autocomplete, not the entire ATK toolbox
8
+ require File.dirname(Gem.find_latest_files('atk_toolbox')[0])+"/atk/autocomplete.rb"; Atk.autocomplete('_')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atk_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.108
4
+ version: 0.0.109
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Hykin
@@ -97,6 +97,7 @@ extensions: []
97
97
  extra_rdoc_files: []
98
98
  files:
99
99
  - lib/atk/atk_info.rb
100
+ - lib/atk/autocomplete.rb
100
101
  - lib/atk/commands/project.rb
101
102
  - lib/atk/console.rb
102
103
  - lib/atk/default_info.yaml