confc 0.0.1 → 0.1.0

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
  SHA256:
3
- metadata.gz: 873beac706039c29977ef938c5ff8eb7feb8c0f8b06b6efb1d97c852bf47af39
4
- data.tar.gz: 1418947b3de04db1a966309e33502e7a8948f97d1deecbaeef60db6704849642
3
+ metadata.gz: 1c3a8dce914874cf543e07abaf7213ef912e7e967bafbcdb03e392a98d3ddbbc
4
+ data.tar.gz: 1ef93bd3d41ab029e994aa3e2784526b09f4088e5e9a2edd421ca4f24193004d
5
5
  SHA512:
6
- metadata.gz: 0a6b944fd9a5d9f1d8ff557604a9ae86e818d2d032d73e6ffa78aa207da82d6c207b1365ab0e56f885ec88e1faff8e707cdd3348ddce7590a6f749514e1f7448
7
- data.tar.gz: aa149ab5f16cc2e0d059683ae1c972a0440a3d183cb48af3ac03eebab838dd7bf81e204591b4709663ea45754309169a28703e3e6ded8e7cb469a1d0d221aefc
6
+ metadata.gz: e65db62da4db911ee9aaa637fbaa218d4da7a5752a90cfd8dade549e19c206e4030561db321b722c47e72f4ba7b31e9df6a200127b9cd40e91d701afcfa7e749
7
+ data.tar.gz: cd460bf49cdf8505e21593737b55360979e7ab42e2288b678d484d4b6fbd162be93304415e4b36fc1455cb6114d080e9dda89cc69e5e8a239fded9b7d5c7903a
data/README.md CHANGED
@@ -20,8 +20,9 @@ gem install confc
20
20
  Usage: confc [options] [filenames...]
21
21
 
22
22
  Clone your default configuration files to current working directory.
23
- -f, --overwrite Force to overwrite
24
23
  -p, --path [PATH] Path to configuration files
24
+ -f, --overwrite Force to overwrite
25
+ -y, --yes Say yes without inquiry
25
26
  -v, --verbose Display more information
26
27
  -V, --version Show version number
27
28
  -h, --help Show help
data/confc.gemspec CHANGED
@@ -18,15 +18,16 @@ Gem::Specification.new do |s|
18
18
  s.required_ruby_version = '>= 2.1.0'
19
19
  s.author = 'Saran Tanpituckpong'
20
20
  s.license = 'MIT'
21
- s.homepage = 'https://github.com/gluons/ConfC.gem'
21
+ s.homepage = 'https://gluons.github.io/ConfC.gem/'
22
22
  s.metadata = {
23
23
  'bug_tracker_uri' => 'https://github.com/gluons/ConfC.gem/issues'
24
24
  }
25
25
 
26
- s.add_runtime_dependency 'rainbow', '~> 2.2', '>= 2.2.2'
26
+ s.add_runtime_dependency 'rainbow', '~> 3.0'
27
+ s.add_runtime_dependency 'tty-prompt', '~> 0.13.2'
27
28
 
28
29
  s.add_development_dependency 'aruba', '~> 0.14.3'
29
30
  s.add_development_dependency 'rake', '~> 12.3'
30
31
  s.add_development_dependency 'rspec', '~> 3.7'
31
- s.add_development_dependency 'rubocop', '~> 0.51.0'
32
+ s.add_development_dependency 'rubocop', '~> 0.52.1'
32
33
  end
@@ -0,0 +1,20 @@
1
+ require 'rainbow'
2
+ require 'tty-prompt'
3
+
4
+ require_relative 'interrupt_handler'
5
+
6
+ APP_NAME = Rainbow('ConfC').green
7
+
8
+ #
9
+ ## ConfC
10
+ module ConfC
11
+ #
12
+ ## Ask to choose existent files to clone.
13
+ def self.ask_choose_files(existent_files)
14
+ prompt = TTY::Prompt.new(interrupt: ConfC::INTERRUPT_HANDLER)
15
+ prompt.multi_select("Which files that you want to #{APP_NAME}?") do |menu|
16
+ menu.default(*(1..existent_files.length))
17
+ menu.choices existent_files
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ require 'rainbow'
2
+ require 'tty-prompt'
3
+
4
+ require_relative 'interrupt_handler'
5
+
6
+ ##
7
+ # ConfC
8
+ module ConfC
9
+ ##
10
+ # Ask to overwrite `dest` file with `src` file.
11
+ def self.ask_overwrite(src, dest)
12
+ colored_src = Rainbow(src).magenta
13
+ colored_dest = Rainbow(dest).green
14
+ prompt = TTY::Prompt.new(interrupt: ConfC::INTERRUPT_HANDLER)
15
+ prompt.yes?(
16
+ %(Do you want to overwrite "#{colored_src}" with "#{colored_dest}"?)
17
+ )
18
+ end
19
+ end
data/lib/confc/cli.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require 'optparse'
2
2
  require 'rainbow'
3
3
 
4
+ require_relative 'ask_choose_files'
4
5
  require_relative 'conf_clone'
5
6
  require_relative 'files'
7
+ require_relative 'get_existent_files'
6
8
  require_relative 'gethome'
7
9
  require_relative 'to_filenames'
8
10
  require_relative 'version'
@@ -19,6 +21,7 @@ DEFAULT_OPTIONS = {
19
21
  files: ConfC.files,
20
22
  path: ConfC.gethome,
21
23
  overwrite: false,
24
+ yes: false,
22
25
  verbose: false
23
26
  }.freeze
24
27
 
@@ -27,6 +30,8 @@ AWW = '(。◕‿◕。)'.freeze
27
30
  ##
28
31
  # ConfC
29
32
  module ConfC
33
+ # rubocop:disable Metrics/MethodLength, Metrics/LineLength, Metrics/AbcSize
34
+
30
35
  ##
31
36
  # ConfC's CLI class.
32
37
  class CLI
@@ -37,14 +42,16 @@ module ConfC
37
42
  files = options[:files]
38
43
 
39
44
  confc_options = {
40
- verbose: options[:verbose],
41
- overwrite: options[:overwrite]
45
+ overwrite: options[:overwrite],
46
+ yes: options[:yes],
47
+ verbose: options[:verbose]
42
48
  }
43
- confc_result = ConfC.conf_clone(files, options[:path], confc_options)
49
+ existent_files = ConfC.get_existent_files(options[:path], files)
50
+ chosen_files = options[:yes] ? existent_files : ConfC.ask_choose_files(existent_files)
51
+ confc_result = ConfC.conf_clone(chosen_files, options[:path], confc_options)
44
52
  puts Rainbow("ConfC completed. #{AWW}").green if confc_result
45
53
  end
46
54
 
47
- # rubocop:disable Metrics/MethodLength, Metrics/LineLength, Metrics/AbcSize
48
55
  ##
49
56
  # Parse CLI ARGV.
50
57
  def self.parse(argv)
@@ -53,11 +60,14 @@ module ConfC
53
60
  parser = OptionParser.new do |opts|
54
61
  opts.banner = BANNER
55
62
 
63
+ opts.on('-p', '--path [PATH]', String, 'Path to configuration files') do |p|
64
+ options[:path] = p
65
+ end
56
66
  opts.on('-f', '--overwrite', 'Force to overwrite') do
57
67
  options[:overwrite] = true
58
68
  end
59
- opts.on('-p', '--path [PATH]', String, 'Path to configuration files') do |p|
60
- options[:path] = p
69
+ opts.on('-y', '--yes', 'Say yes without inquiry') do
70
+ options[:yes] = true
61
71
  end
62
72
  opts.on('-v', '--verbose', 'Display more information') do
63
73
  options[:verbose] = true
@@ -76,6 +86,7 @@ module ConfC
76
86
 
77
87
  options
78
88
  end
89
+
79
90
  # rubocop:enable Metrics/MethodLength, Metrics/LineLength, Metrics/AbcSize
80
91
  end
81
92
  end
@@ -8,7 +8,7 @@ module ConfC
8
8
  def self.conf_clone(
9
9
  files,
10
10
  path,
11
- options = { verbose: false, overwrite: false }
11
+ options = { overwrite: false, verbose: false }
12
12
  )
13
13
  results = files.map do |file|
14
14
  src = File.expand_path(file, path)
data/lib/confc/copy.rb CHANGED
@@ -1,20 +1,34 @@
1
1
  require 'fileutils'
2
2
 
3
+ require_relative 'ask_overwrite'
3
4
  require_relative 'display_verbose'
4
5
  require_relative 'gethome'
5
6
 
6
7
  ##
7
8
  # ConfC
8
9
  module ConfC
10
+ ##
11
+ # Should stop copying?
12
+ def self.should_stop_copying?(
13
+ src,
14
+ dest_path,
15
+ options = { overwrite: false }
16
+ )
17
+ # When dest file exist & no `overwrite`, ask to overwrite.
18
+ File.exist?(dest_path) && !options[:overwrite] &&
19
+ # When answer "don't overwrite", stop!.
20
+ !ConfC.ask_overwrite(src, dest_path)
21
+ end
22
+
9
23
  ##
10
24
  # Copy given file to current working directory.
11
- def self.copy(src, options = { verbose: false, overwrite: false })
25
+ def self.copy(src, options = { overwrite: false, verbose: false })
12
26
  return false unless File.exist?(src) # Stop if no src file
13
27
 
14
28
  # Stop if dest file exists & prevent overwriting
15
29
  src_filename = File.basename(src)
16
30
  dest_path = File.expand_path(src_filename, Dir.pwd)
17
- return false if File.exist?(dest_path) && !options[:overwrite]
31
+ return false if ConfC.should_stop_copying?(src, dest_path, options)
18
32
 
19
33
  FileUtils.copy(src, Dir.pwd)
20
34
 
@@ -0,0 +1,16 @@
1
+ ##
2
+ # ConfC
3
+ module ConfC
4
+ ##
5
+ # Get the existent files at given path from all file list.
6
+ def self.get_existent_files(path, all_files)
7
+ if all_files.is_a?(Array)
8
+ all_files.select do |file|
9
+ file_path = File.expand_path(file, path)
10
+ File.exist?(file_path)
11
+ end
12
+ else
13
+ []
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ require 'rainbow'
2
+
3
+ WTF = '(╯°□°)╯︵ ┻━┻'.freeze
4
+
5
+ ##
6
+ # ConfC
7
+ module ConfC
8
+ INTERRUPT_HANDLER = proc {
9
+ puts
10
+ puts Rainbow("ConfC stopped. #{WTF}").yellow
11
+ exit(1)
12
+ }
13
+ end
data/lib/confc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ConfC
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: confc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saran Tanpituckpong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-17 00:00:00.000000000 Z
11
+ date: 2017-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -16,20 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.2'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.2.2
19
+ version: '3.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '2.2'
30
- - - ">="
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-prompt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.13.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
31
39
  - !ruby/object:Gem::Version
32
- version: 2.2.2
40
+ version: 0.13.2
33
41
  - !ruby/object:Gem::Dependency
34
42
  name: aruba
35
43
  requirement: !ruby/object:Gem::Requirement
@@ -78,14 +86,14 @@ dependencies:
78
86
  requirements:
79
87
  - - "~>"
80
88
  - !ruby/object:Gem::Version
81
- version: 0.51.0
89
+ version: 0.52.1
82
90
  type: :development
83
91
  prerelease: false
84
92
  version_requirements: !ruby/object:Gem::Requirement
85
93
  requirements:
86
94
  - - "~>"
87
95
  - !ruby/object:Gem::Version
88
- version: 0.51.0
96
+ version: 0.52.1
89
97
  description: Clone your default configuration files to current working directory.
90
98
  email:
91
99
  executables:
@@ -100,15 +108,19 @@ files:
100
108
  - confc.gemspec
101
109
  - files.yaml
102
110
  - lib/confc.rb
111
+ - lib/confc/ask_choose_files.rb
112
+ - lib/confc/ask_overwrite.rb
103
113
  - lib/confc/cli.rb
104
114
  - lib/confc/conf_clone.rb
105
115
  - lib/confc/copy.rb
106
116
  - lib/confc/display_verbose.rb
107
117
  - lib/confc/files.rb
118
+ - lib/confc/get_existent_files.rb
108
119
  - lib/confc/gethome.rb
120
+ - lib/confc/interrupt_handler.rb
109
121
  - lib/confc/to_filenames.rb
110
122
  - lib/confc/version.rb
111
- homepage: https://github.com/gluons/ConfC.gem
123
+ homepage: https://gluons.github.io/ConfC.gem/
112
124
  licenses:
113
125
  - MIT
114
126
  metadata: