central 0.2.3 → 0.2.4

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/central +1 -1
  3. data/lib/central.rb +23 -29
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c28cbd68d80c217678f5b6d81dc82cd2d4de4eed
4
- data.tar.gz: 152e89721d347f991b177e6e81165619c3bfff70
3
+ metadata.gz: 59a223e19b875e1e3d7dc50f70f60697816d47e3
4
+ data.tar.gz: 8037442fffcaaccbe55bf1209dae265890432836
5
5
  SHA512:
6
- metadata.gz: b873dba32172c267f1419657c5d500736880dbcfe9f04b431984e489406e91ac55a809c9358bb71a361f1f5bf120e238cdf89dc5ee91d9fda7c8bd1c76070dcc
7
- data.tar.gz: 70e5070de43a592bb09234e82e130025516139fbea193caf0cc6d1892ca9a90f98681b83be4118670a3ee01f0fdafcb6d738bf8f61ec2ae6e1a6d6e3a9796d4d
6
+ metadata.gz: 1ef58f6d6da2bf0f3148677cc86d5cf5779c4d2fa766102c1dfd5cd4ac5aad643d7e55ed78a575b83a6e2d38735bfefdc0bb8a6eebe5935dde1ec4326bf03fa6
7
+ data.tar.gz: 025ab8f80c6e4cc29038ff1cacb276206527da789865732539d64887b23b590007c9debe723ab7224ed02de28ac705be2a331cdeaf04ae568ed7a1ade5392858
data/bin/central CHANGED
@@ -10,7 +10,7 @@ require 'central'
10
10
 
11
11
  if ARGV.length > 0
12
12
  if ARGV[0] == '-v' || ARGV[0] == '--version' || ARGV[0] == '-version'
13
- puts "central v0.2.2"
13
+ puts "central v0.2.4"
14
14
  exit 0
15
15
  end
16
16
  if ARGV[0] == '-h' || ARGV[0] == '--help' || ARGV[0] == '-help'
data/lib/central.rb CHANGED
@@ -45,9 +45,8 @@ end
45
45
 
46
46
  # run shell command and get output, optionaly can print command running if verbose and if not silent will also print to stdout and stderr
47
47
  $shell_return_value = nil
48
- def shell(command,options={:verbose => false, :silent => true})
49
- silent = options[:silent]
50
- puts "Executing: #{command}" if options[:verbose]
48
+ def shell(command,verbose: false, silent: true)
49
+ puts "Executing: #{command}" if verbose
51
50
  stdout = ''
52
51
  stdout_line = ''
53
52
  stderr = ''
@@ -101,8 +100,8 @@ def shell(command,options={:verbose => false, :silent => true})
101
100
  end
102
101
 
103
102
  # run shell command with sudo prefix, acts same as shell
104
- def sudo(command,options)
105
- return shell('sudo '+command, options)
103
+ def sudo(command,verbose:,silent:)
104
+ return shell('sudo '+command, verbose: verbose, silent: silent)
106
105
  end
107
106
 
108
107
  # function used to check that system has all required tools installed
@@ -151,7 +150,7 @@ end
151
150
  # check if directory exists
152
151
  def dir_exists?(path)
153
152
  path = abs(path)
154
- Dir.exists?(path)
153
+ Dir.exist?(path)
155
154
  end
156
155
 
157
156
  # get directory name of a file
@@ -184,7 +183,7 @@ def mkdir(path)
184
183
  end
185
184
 
186
185
  # remove file/directory
187
- def rm(path,recursive=false)
186
+ def rm(path,recursive: false)
188
187
  path = abs(path)
189
188
  if recursive
190
189
  recursive = '-R '
@@ -210,7 +209,7 @@ end
210
209
 
211
210
  # remove directory recursively
212
211
  def rmdir(path)
213
- rm(path,true)
212
+ rm(path,recursive: true)
214
213
  end
215
214
 
216
215
  # touch file
@@ -228,7 +227,7 @@ def touch(path)
228
227
  end
229
228
 
230
229
  # change file permissions
231
- def chmod(path,permissions,recursive=false)
230
+ def chmod(path,permissions,recursive: false)
232
231
  path = abs(path)
233
232
  if recursive
234
233
  recursive = '-R '
@@ -265,7 +264,7 @@ def symlink(from,to)
265
264
  end
266
265
 
267
266
  # git clone url into a path
268
- def git(url,path,branch=nil,silent=false)
267
+ def git(url,path,branch: nil,silent: false,depth: nil)
269
268
  path = abs(path)
270
269
  if dir_exists?(path) && dir_exists?("#{path}/.git")
271
270
  cwd = pwd()
@@ -295,24 +294,27 @@ def git(url,path,branch=nil,silent=false)
295
294
  else
296
295
  branch = ''
297
296
  end
298
- out = shell("git clone #{branch}#{url} \"#{path}\" 2>&1",{:silent => silent})
297
+ if depth
298
+ depth = '--depth '+depth.to_s+' '
299
+ else
300
+ depth = ''
301
+ end
302
+ out = shell("git clone #{depth}#{branch}#{url} \"#{path}\" 2>&1",{:silent => silent})
299
303
  puts out if silent
300
304
  puts "Git repository cloned: #{url} → #{path}"
301
305
  end
302
306
  end
303
307
 
304
308
  # download url into a path using curl
305
- def curl(url,path,verbose=false)
309
+ def curl(url,path, verbose: false)
306
310
  path = abs(path)
307
- output = shell("curl -s -S \"#{url}\"",{:verbose => verbose, :silent => true})
311
+ puts "Downloading #{url} #{path}"
312
+ output = shell("curl -s -S \"#{url}\"",verbose: verbose, silent: true)
308
313
  unless $shell_return_value.success?
309
314
  STDERR.puts output
310
315
  STDERR.puts "Couldn't download file from #{url}..."
311
316
  exit 1
312
317
  end
313
- if File.exists?(path) && File.read(path) == output
314
- return
315
- end
316
318
  File.write(path,output)
317
319
  puts "Downloaded #{url} → #{path}"
318
320
  end
@@ -347,16 +349,16 @@ def source(file,source)
347
349
  end
348
350
 
349
351
  # list directory content
350
- def ls(path,options={})
352
+ def ls(path,dotfiles: false, grep: '', dir: true, file: true)
351
353
  path = abs(path)
352
- if options[:dotfiles]
354
+ if dotfiles
353
355
  dotfiles = '-a '
354
356
  else
355
357
  dotfiles = ''
356
358
  end
357
359
  command = "ls -1 #{dotfiles}\"#{path}\" 2>&1"
358
- if options.key?(:grep) && options[:grep].length > 0
359
- command += " | grep #{options[:grep]}"
360
+ if grep.length > 0
361
+ command += " | grep #{grep}"
360
362
  end
361
363
  output = shell(command)
362
364
  if output.downcase.end_with?('no such file or directory')
@@ -364,14 +366,6 @@ def ls(path,options={})
364
366
  exit 1
365
367
  end
366
368
  ls = output.split("\n")
367
- dir = true
368
- file = true
369
- if options.key?(:dir)
370
- dir = options[:dir]
371
- end
372
- if options.key?(:file)
373
- file = options[:file]
374
- end
375
369
  unless dir
376
370
  ls = ls.keep_if {|f| !File.directory?("#{path}/#{f}") }
377
371
  end
@@ -414,7 +408,7 @@ def erb(file,output_file = nil)
414
408
  end
415
409
  if file_exists?(file)
416
410
  output = ERB.new(File.read(file)).result
417
- if File.exists?(output_file) && File.read(output_file) == output
411
+ if File.exist?(output_file) && File.read(output_file) == output
418
412
  return
419
413
  end
420
414
  File.write(output_file,output)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: central
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Geurkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-14 00:00:00.000000000 Z
11
+ date: 2019-05-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: central dotfile management system
14
14
  email: d.geurkov@gmail.com
@@ -39,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
39
  version: '0'
40
40
  requirements: []
41
41
  rubyforge_project:
42
- rubygems_version: 2.5.2
42
+ rubygems_version: 2.5.2.1
43
43
  signing_key:
44
44
  specification_version: 4
45
45
  summary: central dotfile management