confc 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/LICENSE +21 -21
- data/README.md +66 -65
- data/bin/confc +5 -5
- data/confc.gemspec +35 -35
- data/files.yaml +8 -8
- data/lib/confc.rb +7 -7
- data/lib/confc/ask_choose_files.rb +20 -20
- data/lib/confc/ask_overwrite.rb +19 -19
- data/lib/confc/cli.rb +85 -85
- data/lib/confc/conf_clone.rb +19 -19
- data/lib/confc/copy.rb +41 -41
- data/lib/confc/display_verbose.rb +17 -17
- data/lib/confc/files.rb +16 -16
- data/lib/confc/get_existent_files.rb +16 -16
- data/lib/confc/gethome.rb +9 -9
- data/lib/confc/interrupt_handler.rb +13 -13
- data/lib/confc/load_config.rb +31 -31
- data/lib/confc/to_filenames.rb +15 -15
- data/lib/confc/version.rb +3 -3
- metadata +11 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 153aeb316fc9fced39a8d8fcfcde52f55f0b1caa309654a470d526c319218005
|
4
|
+
data.tar.gz: 0dd2595923dbd5c56f1148a6659f0c54cc51aedafaaf55c9432226de07efce8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb5b171079228f4c2d4ffa9bf27c9f5874a324526d68c04122645878d25e36c429c5ea694af5e633e531a2c444963d3e806c4c4c2367e3e52b2f7bd96463c293
|
7
|
+
data.tar.gz: acaca7692f694f5e9f812b4fe1a8c85498e0ed52a779d88661aa6d1ed58e89fb592762e9c3f24083ad703faa8f8a989517956bffd1981a82317ff953ea3519e3
|
data/Gemfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
data/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2017 Saran Tanpituckpong
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Saran Tanpituckpong
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,65 +1,66 @@
|
|
1
|
-
# ConfC
|
2
|
-
[![license](https://img.shields.io/github/license/gluons/ConfC.gem.svg?style=flat-square)](./LICENSE)
|
3
|
-
[![Gem](https://img.shields.io/gem/v/confc.svg?style=flat-square)](https://rubygems.org/gems/confc)
|
4
|
-
[![Gem](https://img.shields.io/gem/dt/confc.svg?style=flat-square)](https://rubygems.org/gems/confc)
|
5
|
-
[![
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
-
|
25
|
-
-
|
26
|
-
-
|
27
|
-
-
|
28
|
-
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
1
|
+
# ConfC
|
2
|
+
[![license](https://img.shields.io/github/license/gluons/ConfC.gem.svg?style=flat-square)](./LICENSE)
|
3
|
+
[![Gem](https://img.shields.io/gem/v/confc.svg?style=flat-square)](https://rubygems.org/gems/confc)
|
4
|
+
[![Gem](https://img.shields.io/gem/dt/confc.svg?style=flat-square)](https://rubygems.org/gems/confc)
|
5
|
+
[![Libraries.io for GitHub](https://img.shields.io/librariesio/github/gluons/ConfC.gem.svg?style=flat-square)](https://libraries.io/github/gluons/ConfC.gem)
|
6
|
+
[![Travis](https://img.shields.io/travis/gluons/ConfC.gem.svg?style=flat-square)](https://travis-ci.org/gluons/ConfC.gem)
|
7
|
+
|
8
|
+
**Config Clone** — 🆕 Start new project with your default configs.
|
9
|
+
|
10
|
+
Clone your default configuration files to current working directory.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
```bash
|
15
|
+
gem install confc
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
```
|
21
|
+
Usage: confc [options] [filenames...]
|
22
|
+
|
23
|
+
Clone your default configuration files to current working directory.
|
24
|
+
-p, --path [PATH] Path to configuration files
|
25
|
+
-f, --overwrite Force to overwrite
|
26
|
+
-y, --yes Say yes without inquiry
|
27
|
+
-v, --verbose Display more information
|
28
|
+
-V, --version Show version number
|
29
|
+
-h, --help Show help
|
30
|
+
```
|
31
|
+
|
32
|
+
## Configuration
|
33
|
+
|
34
|
+
You can configure **ConfC** via `.confcrc`, `.confcrc.json`, `.confcrc.yml` or `.confcrc.yaml` file.
|
35
|
+
More information about configuration file can be found from [mysticonfig](https://git.io/mysticonfig).
|
36
|
+
|
37
|
+
### .confcrc
|
38
|
+
- **path**
|
39
|
+
Type: `String`
|
40
|
+
Default: **$HOME** (Your **home** directory)
|
41
|
+
|
42
|
+
Path to directory that contain your default configuration files.
|
43
|
+
|
44
|
+
- **files**
|
45
|
+
Type: `Array<String>`
|
46
|
+
Default: Files name in [files.yaml](./files.yaml)
|
47
|
+
|
48
|
+
List of target files name that you want to clone.
|
49
|
+
|
50
|
+
> If you have your own configuration files and don't want to use files from [files.yaml](./files.yaml), just replace it with your files name by this option.
|
51
|
+
|
52
|
+
- **overwrite**
|
53
|
+
Type: `Boolean`
|
54
|
+
Default: `false`
|
55
|
+
|
56
|
+
Force to overwrite files if it exists.
|
57
|
+
|
58
|
+
- **verbose**
|
59
|
+
Type: `Boolean`
|
60
|
+
Default: `false`
|
61
|
+
|
62
|
+
Display verbose information.
|
63
|
+
|
64
|
+
## Related
|
65
|
+
|
66
|
+
- [ConfC](https://github.com/gluons/ConfC) - 🆕 Start new project with your default configs. (Node.js version)
|
data/bin/confc
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'confc'
|
4
|
-
|
5
|
-
ConfC::CLI.start(ARGV)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'confc'
|
4
|
+
|
5
|
+
ConfC::CLI.start(ARGV)
|
data/confc.gemspec
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
lib = File.expand_path('./lib', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
$LOAD_PATH.push lib unless $LOAD_PATH.include?(lib)
|
4
|
-
|
5
|
-
require 'confc/version'
|
6
|
-
|
7
|
-
DESCRIPTION =
|
8
|
-
'Clone your default configuration files to current working directory.'.freeze
|
9
|
-
|
10
|
-
Gem::Specification.new do |s|
|
11
|
-
s.name = 'confc'
|
12
|
-
s.version = ConfC::VERSION
|
13
|
-
s.summary = 'Start new project with your default configs.'
|
14
|
-
s.description = DESCRIPTION
|
15
|
-
s.files = ['confc.gemspec', 'LICENSE', 'Gemfile', 'files.yaml']
|
16
|
-
s.files += Dir['*.md', 'bin/*', 'lib/**/*']
|
17
|
-
s.executables = ['confc']
|
18
|
-
s.required_ruby_version = '>= 2.2.2'
|
19
|
-
s.author = 'Saran Tanpituckpong'
|
20
|
-
s.license = 'MIT'
|
21
|
-
s.homepage = 'https://gluons.github.io/ConfC.gem/'
|
22
|
-
s.metadata = {
|
23
|
-
'bug_tracker_uri' => 'https://github.com/gluons/ConfC.gem/issues'
|
24
|
-
}
|
25
|
-
|
26
|
-
s.add_runtime_dependency 'activesupport', '~> 5.
|
27
|
-
s.add_runtime_dependency 'mysticonfig', '~> 0.1.
|
28
|
-
s.add_runtime_dependency 'rainbow', '~> 3.0'
|
29
|
-
s.add_runtime_dependency 'tty-prompt', '~> 0.
|
30
|
-
|
31
|
-
s.add_development_dependency 'aruba', '~> 0.14.3'
|
32
|
-
s.add_development_dependency 'rake', '~> 12.3'
|
33
|
-
s.add_development_dependency 'rspec', '~> 3.7'
|
34
|
-
s.add_development_dependency 'rubocop', '~> 0.
|
35
|
-
end
|
1
|
+
lib = File.expand_path('./lib', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
$LOAD_PATH.push lib unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'confc/version'
|
6
|
+
|
7
|
+
DESCRIPTION =
|
8
|
+
'Clone your default configuration files to current working directory.'.freeze
|
9
|
+
|
10
|
+
Gem::Specification.new do |s|
|
11
|
+
s.name = 'confc'
|
12
|
+
s.version = ConfC::VERSION
|
13
|
+
s.summary = 'Start new project with your default configs.'
|
14
|
+
s.description = DESCRIPTION
|
15
|
+
s.files = ['confc.gemspec', 'LICENSE', 'Gemfile', 'files.yaml']
|
16
|
+
s.files += Dir['*.md', 'bin/*', 'lib/**/*']
|
17
|
+
s.executables = ['confc']
|
18
|
+
s.required_ruby_version = '>= 2.2.2'
|
19
|
+
s.author = 'Saran Tanpituckpong'
|
20
|
+
s.license = 'MIT'
|
21
|
+
s.homepage = 'https://gluons.github.io/ConfC.gem/'
|
22
|
+
s.metadata = {
|
23
|
+
'bug_tracker_uri' => 'https://github.com/gluons/ConfC.gem/issues'
|
24
|
+
}
|
25
|
+
|
26
|
+
s.add_runtime_dependency 'activesupport', '~> 5.2'
|
27
|
+
s.add_runtime_dependency 'mysticonfig', '~> 0.1.1'
|
28
|
+
s.add_runtime_dependency 'rainbow', '~> 3.0'
|
29
|
+
s.add_runtime_dependency 'tty-prompt', '~> 0.16.1'
|
30
|
+
|
31
|
+
s.add_development_dependency 'aruba', '~> 0.14.3'
|
32
|
+
s.add_development_dependency 'rake', '~> 12.3'
|
33
|
+
s.add_development_dependency 'rspec', '~> 3.7'
|
34
|
+
s.add_development_dependency 'rubocop', '~> 0.55.0'
|
35
|
+
end
|
data/files.yaml
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
---
|
2
|
-
|
3
|
-
- .bowerrc
|
4
|
-
- .editorconfig
|
5
|
-
- .eslintrc.json
|
6
|
-
- .prettierrc
|
7
|
-
- coffeelint.json
|
8
|
-
- tslint.json
|
1
|
+
---
|
2
|
+
|
3
|
+
- .bowerrc
|
4
|
+
- .editorconfig
|
5
|
+
- .eslintrc.json
|
6
|
+
- .prettierrc
|
7
|
+
- coffeelint.json
|
8
|
+
- tslint.json
|
data/lib/confc.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# Path to ./confc
|
2
|
-
confc_lib = File.expand_path('./confc', File.dirname(__FILE__))
|
3
|
-
|
4
|
-
# All files exclude . and ..
|
5
|
-
lib_files = Dir.entries(confc_lib).reject { |f| f =~ /^(\.|\.\.)$/ }
|
6
|
-
|
7
|
-
lib_files.each { |f| require_relative "confc/#{f}" }
|
1
|
+
# Path to ./confc
|
2
|
+
confc_lib = File.expand_path('./confc', File.dirname(__FILE__))
|
3
|
+
|
4
|
+
# All files exclude . and ..
|
5
|
+
lib_files = Dir.entries(confc_lib).reject { |f| f =~ /^(\.|\.\.)$/ }
|
6
|
+
|
7
|
+
lib_files.each { |f| require_relative "confc/#{f}" }
|
@@ -1,20 +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
|
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
|
data/lib/confc/ask_overwrite.rb
CHANGED
@@ -1,19 +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
|
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,85 +1,85 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'rainbow'
|
3
|
-
|
4
|
-
require_relative 'ask_choose_files'
|
5
|
-
require_relative 'conf_clone'
|
6
|
-
require_relative 'files'
|
7
|
-
require_relative 'get_existent_files'
|
8
|
-
require_relative 'gethome'
|
9
|
-
require_relative 'load_config'
|
10
|
-
require_relative 'to_filenames'
|
11
|
-
require_relative 'version'
|
12
|
-
|
13
|
-
# rubocop:disable Layout/IndentHeredoc
|
14
|
-
BANNER = <<-BANNER.freeze
|
15
|
-
Usage: #{Rainbow('confc').green} [options] [filenames...]
|
16
|
-
|
17
|
-
Clone your default configuration files to current working directory.
|
18
|
-
|
19
|
-
BANNER
|
20
|
-
# rubocop:enable Layout/IndentHeredoc
|
21
|
-
|
22
|
-
AWW = '(。◕‿◕。)'.freeze
|
23
|
-
|
24
|
-
##
|
25
|
-
# ConfC
|
26
|
-
module ConfC
|
27
|
-
# rubocop:disable Metrics/MethodLength, Metrics/LineLength, Metrics/AbcSize
|
28
|
-
|
29
|
-
##
|
30
|
-
# ConfC's CLI class.
|
31
|
-
class CLI
|
32
|
-
##
|
33
|
-
# Start CLI.
|
34
|
-
def self.start(argv)
|
35
|
-
options = CLI.parse(argv)
|
36
|
-
files = options[:files]
|
37
|
-
|
38
|
-
confc_options = {
|
39
|
-
overwrite: options[:overwrite],
|
40
|
-
verbose: options[:verbose]
|
41
|
-
}
|
42
|
-
existent_files = ConfC.get_existent_files(options[:path], files)
|
43
|
-
chosen_files = options[:yes] ? existent_files : ConfC.ask_choose_files(existent_files)
|
44
|
-
confc_result = ConfC.conf_clone(chosen_files, options[:path], confc_options)
|
45
|
-
puts Rainbow("ConfC completed. #{AWW}").green if confc_result
|
46
|
-
end
|
47
|
-
|
48
|
-
##
|
49
|
-
# Parse CLI ARGV.
|
50
|
-
def self.parse(argv)
|
51
|
-
options = ConfC.load_config
|
52
|
-
|
53
|
-
parser = OptionParser.new do |opts|
|
54
|
-
opts.banner = BANNER
|
55
|
-
|
56
|
-
opts.on('-p', '--path [PATH]', String, 'Path to configuration files') do |p|
|
57
|
-
options[:path] = p
|
58
|
-
end
|
59
|
-
opts.on('-f', '--overwrite', 'Force to overwrite') do
|
60
|
-
options[:overwrite] = true
|
61
|
-
end
|
62
|
-
opts.on('-y', '--yes', 'Say yes without inquiry') do
|
63
|
-
options[:yes] = true
|
64
|
-
end
|
65
|
-
opts.on('-v', '--verbose', 'Display more information') do
|
66
|
-
options[:verbose] = true
|
67
|
-
end
|
68
|
-
opts.on('-V', '--version', 'Show version number') do
|
69
|
-
puts "v#{ConfC::VERSION}"
|
70
|
-
exit
|
71
|
-
end
|
72
|
-
opts.on('-h', '--help', 'Show help') do
|
73
|
-
puts opts
|
74
|
-
exit
|
75
|
-
end
|
76
|
-
end
|
77
|
-
files = parser.parse(argv)
|
78
|
-
options[:files] = ConfC.to_filenames(files) if files.is_a?(Array) && !files.empty?
|
79
|
-
|
80
|
-
options
|
81
|
-
end
|
82
|
-
|
83
|
-
# rubocop:enable Metrics/MethodLength, Metrics/LineLength, Metrics/AbcSize
|
84
|
-
end
|
85
|
-
end
|
1
|
+
require 'optparse'
|
2
|
+
require 'rainbow'
|
3
|
+
|
4
|
+
require_relative 'ask_choose_files'
|
5
|
+
require_relative 'conf_clone'
|
6
|
+
require_relative 'files'
|
7
|
+
require_relative 'get_existent_files'
|
8
|
+
require_relative 'gethome'
|
9
|
+
require_relative 'load_config'
|
10
|
+
require_relative 'to_filenames'
|
11
|
+
require_relative 'version'
|
12
|
+
|
13
|
+
# rubocop:disable Layout/IndentHeredoc
|
14
|
+
BANNER = <<-BANNER.freeze
|
15
|
+
Usage: #{Rainbow('confc').green} [options] [filenames...]
|
16
|
+
|
17
|
+
Clone your default configuration files to current working directory.
|
18
|
+
|
19
|
+
BANNER
|
20
|
+
# rubocop:enable Layout/IndentHeredoc
|
21
|
+
|
22
|
+
AWW = '(。◕‿◕。)'.freeze
|
23
|
+
|
24
|
+
##
|
25
|
+
# ConfC
|
26
|
+
module ConfC
|
27
|
+
# rubocop:disable Metrics/MethodLength, Metrics/LineLength, Metrics/AbcSize
|
28
|
+
|
29
|
+
##
|
30
|
+
# ConfC's CLI class.
|
31
|
+
class CLI
|
32
|
+
##
|
33
|
+
# Start CLI.
|
34
|
+
def self.start(argv)
|
35
|
+
options = CLI.parse(argv)
|
36
|
+
files = options[:files]
|
37
|
+
|
38
|
+
confc_options = {
|
39
|
+
overwrite: options[:overwrite],
|
40
|
+
verbose: options[:verbose]
|
41
|
+
}
|
42
|
+
existent_files = ConfC.get_existent_files(options[:path], files)
|
43
|
+
chosen_files = options[:yes] ? existent_files : ConfC.ask_choose_files(existent_files)
|
44
|
+
confc_result = ConfC.conf_clone(chosen_files, options[:path], confc_options)
|
45
|
+
puts Rainbow("ConfC completed. #{AWW}").green if confc_result
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Parse CLI ARGV.
|
50
|
+
def self.parse(argv)
|
51
|
+
options = ConfC.load_config
|
52
|
+
|
53
|
+
parser = OptionParser.new do |opts|
|
54
|
+
opts.banner = BANNER
|
55
|
+
|
56
|
+
opts.on('-p', '--path [PATH]', String, 'Path to configuration files') do |p|
|
57
|
+
options[:path] = p
|
58
|
+
end
|
59
|
+
opts.on('-f', '--overwrite', 'Force to overwrite') do
|
60
|
+
options[:overwrite] = true
|
61
|
+
end
|
62
|
+
opts.on('-y', '--yes', 'Say yes without inquiry') do
|
63
|
+
options[:yes] = true
|
64
|
+
end
|
65
|
+
opts.on('-v', '--verbose', 'Display more information') do
|
66
|
+
options[:verbose] = true
|
67
|
+
end
|
68
|
+
opts.on('-V', '--version', 'Show version number') do
|
69
|
+
puts "v#{ConfC::VERSION}"
|
70
|
+
exit
|
71
|
+
end
|
72
|
+
opts.on('-h', '--help', 'Show help') do
|
73
|
+
puts opts
|
74
|
+
exit
|
75
|
+
end
|
76
|
+
end
|
77
|
+
files = parser.parse(argv)
|
78
|
+
options[:files] = ConfC.to_filenames(files) if files.is_a?(Array) && !files.empty?
|
79
|
+
|
80
|
+
options
|
81
|
+
end
|
82
|
+
|
83
|
+
# rubocop:enable Metrics/MethodLength, Metrics/LineLength, Metrics/AbcSize
|
84
|
+
end
|
85
|
+
end
|
data/lib/confc/conf_clone.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
require_relative 'copy'
|
2
|
-
|
3
|
-
##
|
4
|
-
# ConfC
|
5
|
-
module ConfC
|
6
|
-
##
|
7
|
-
# Clone given files from given path to current working directory.
|
8
|
-
def self.conf_clone(
|
9
|
-
files,
|
10
|
-
path,
|
11
|
-
options = { overwrite: false, verbose: false }
|
12
|
-
)
|
13
|
-
results = files.map do |file|
|
14
|
-
src = File.expand_path(file, path)
|
15
|
-
ConfC.copy(src, options)
|
16
|
-
end
|
17
|
-
results.any? { |result| result } # Return true if any process succeed
|
18
|
-
end
|
19
|
-
end
|
1
|
+
require_relative 'copy'
|
2
|
+
|
3
|
+
##
|
4
|
+
# ConfC
|
5
|
+
module ConfC
|
6
|
+
##
|
7
|
+
# Clone given files from given path to current working directory.
|
8
|
+
def self.conf_clone(
|
9
|
+
files,
|
10
|
+
path,
|
11
|
+
options = { overwrite: false, verbose: false }
|
12
|
+
)
|
13
|
+
results = files.map do |file|
|
14
|
+
src = File.expand_path(file, path)
|
15
|
+
ConfC.copy(src, options)
|
16
|
+
end
|
17
|
+
results.any? { |result| result } # Return true if any process succeed
|
18
|
+
end
|
19
|
+
end
|
data/lib/confc/copy.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
require_relative 'ask_overwrite'
|
4
|
-
require_relative 'display_verbose'
|
5
|
-
require_relative 'gethome'
|
6
|
-
|
7
|
-
##
|
8
|
-
# ConfC
|
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
|
-
|
23
|
-
##
|
24
|
-
# Copy given file to current working directory.
|
25
|
-
def self.copy(src, options = { overwrite: false, verbose: false })
|
26
|
-
return false unless File.exist?(src) # Stop if no src file
|
27
|
-
|
28
|
-
# Stop if dest file exists & prevent overwriting
|
29
|
-
src_filename = File.basename(src)
|
30
|
-
dest_path = File.expand_path(src_filename, Dir.pwd)
|
31
|
-
return false if ConfC.should_stop_copying?(src, dest_path, options)
|
32
|
-
|
33
|
-
FileUtils.copy(src, Dir.pwd)
|
34
|
-
|
35
|
-
# Display verbose
|
36
|
-
dest = File.expand_path(src_filename, Dir.pwd)
|
37
|
-
ConfC.display_verbose(src, dest) if options[:verbose]
|
38
|
-
|
39
|
-
true
|
40
|
-
end
|
41
|
-
end
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require_relative 'ask_overwrite'
|
4
|
+
require_relative 'display_verbose'
|
5
|
+
require_relative 'gethome'
|
6
|
+
|
7
|
+
##
|
8
|
+
# ConfC
|
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
|
+
|
23
|
+
##
|
24
|
+
# Copy given file to current working directory.
|
25
|
+
def self.copy(src, options = { overwrite: false, verbose: false })
|
26
|
+
return false unless File.exist?(src) # Stop if no src file
|
27
|
+
|
28
|
+
# Stop if dest file exists & prevent overwriting
|
29
|
+
src_filename = File.basename(src)
|
30
|
+
dest_path = File.expand_path(src_filename, Dir.pwd)
|
31
|
+
return false if ConfC.should_stop_copying?(src, dest_path, options)
|
32
|
+
|
33
|
+
FileUtils.copy(src, Dir.pwd)
|
34
|
+
|
35
|
+
# Display verbose
|
36
|
+
dest = File.expand_path(src_filename, Dir.pwd)
|
37
|
+
ConfC.display_verbose(src, dest) if options[:verbose]
|
38
|
+
|
39
|
+
true
|
40
|
+
end
|
41
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
require 'rainbow'
|
2
|
-
|
3
|
-
##
|
4
|
-
# ConfC
|
5
|
-
module ConfC
|
6
|
-
##
|
7
|
-
# Display verbose information.
|
8
|
-
def self.display_verbose(src, dest)
|
9
|
-
verbose = Rainbow('Copied "').green
|
10
|
-
verbose += Rainbow(src).cyan
|
11
|
-
verbose += Rainbow('" to "').green
|
12
|
-
verbose += Rainbow(dest).cyan
|
13
|
-
verbose += Rainbow('".').green
|
14
|
-
|
15
|
-
puts verbose
|
16
|
-
end
|
17
|
-
end
|
1
|
+
require 'rainbow'
|
2
|
+
|
3
|
+
##
|
4
|
+
# ConfC
|
5
|
+
module ConfC
|
6
|
+
##
|
7
|
+
# Display verbose information.
|
8
|
+
def self.display_verbose(src, dest)
|
9
|
+
verbose = Rainbow('Copied "').green
|
10
|
+
verbose += Rainbow(src).cyan
|
11
|
+
verbose += Rainbow('" to "').green
|
12
|
+
verbose += Rainbow(dest).cyan
|
13
|
+
verbose += Rainbow('".').green
|
14
|
+
|
15
|
+
puts verbose
|
16
|
+
end
|
17
|
+
end
|
data/lib/confc/files.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
##
|
4
|
-
# ConfC
|
5
|
-
module ConfC
|
6
|
-
##
|
7
|
-
# Get list of file to be copied.
|
8
|
-
def self.files
|
9
|
-
files_path = File.expand_path('../../files.yaml', File.dirname(__FILE__))
|
10
|
-
if File.exist?(files_path)
|
11
|
-
YAML.load_file(files_path)
|
12
|
-
else
|
13
|
-
[]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
##
|
4
|
+
# ConfC
|
5
|
+
module ConfC
|
6
|
+
##
|
7
|
+
# Get list of file to be copied.
|
8
|
+
def self.files
|
9
|
+
files_path = File.expand_path('../../files.yaml', File.dirname(__FILE__))
|
10
|
+
if File.exist?(files_path)
|
11
|
+
YAML.load_file(files_path)
|
12
|
+
else
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,16 +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
|
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
|
data/lib/confc/gethome.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
##
|
2
|
-
# ConfC
|
3
|
-
module ConfC
|
4
|
-
##
|
5
|
-
# Get user's home directory.
|
6
|
-
def self.gethome
|
7
|
-
File.expand_path '~'
|
8
|
-
end
|
9
|
-
end
|
1
|
+
##
|
2
|
+
# ConfC
|
3
|
+
module ConfC
|
4
|
+
##
|
5
|
+
# Get user's home directory.
|
6
|
+
def self.gethome
|
7
|
+
File.expand_path '~'
|
8
|
+
end
|
9
|
+
end
|
@@ -1,13 +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
|
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/load_config.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
require 'active_support/core_ext/hash/keys'
|
2
|
-
require 'mysticonfig'
|
3
|
-
|
4
|
-
require_relative 'files'
|
5
|
-
require_relative 'gethome'
|
6
|
-
|
7
|
-
DEFAULT_CONFIG = {
|
8
|
-
'path' => ConfC.gethome,
|
9
|
-
'files' => ConfC.files,
|
10
|
-
'overwrite' => false,
|
11
|
-
'verbose' => false,
|
12
|
-
'yes' => false
|
13
|
-
}.freeze
|
14
|
-
|
15
|
-
##
|
16
|
-
# ConfC
|
17
|
-
module ConfC
|
18
|
-
##
|
19
|
-
# Load ConfC configuration.
|
20
|
-
def self.load_config
|
21
|
-
loader = Mysticonfig::Loader.new('confc', DEFAULT_CONFIG)
|
22
|
-
config = loader.load
|
23
|
-
if config.empty?
|
24
|
-
DEFAULT_CONFIG.symbolize_keys
|
25
|
-
else
|
26
|
-
# Truncate un-related config
|
27
|
-
config = config.select { |k, _| DEFAULT_CONFIG.keys.include? k }
|
28
|
-
config.symbolize_keys
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
require 'active_support/core_ext/hash/keys'
|
2
|
+
require 'mysticonfig'
|
3
|
+
|
4
|
+
require_relative 'files'
|
5
|
+
require_relative 'gethome'
|
6
|
+
|
7
|
+
DEFAULT_CONFIG = {
|
8
|
+
'path' => ConfC.gethome,
|
9
|
+
'files' => ConfC.files,
|
10
|
+
'overwrite' => false,
|
11
|
+
'verbose' => false,
|
12
|
+
'yes' => false
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
##
|
16
|
+
# ConfC
|
17
|
+
module ConfC
|
18
|
+
##
|
19
|
+
# Load ConfC configuration.
|
20
|
+
def self.load_config
|
21
|
+
loader = Mysticonfig::Loader.new('confc', DEFAULT_CONFIG)
|
22
|
+
config = loader.load
|
23
|
+
if config.empty?
|
24
|
+
DEFAULT_CONFIG.symbolize_keys
|
25
|
+
else
|
26
|
+
# Truncate un-related config
|
27
|
+
config = config.select { |k, _| DEFAULT_CONFIG.keys.include? k }
|
28
|
+
config.symbolize_keys
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/confc/to_filenames.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
##
|
2
|
-
# ConfC
|
3
|
-
module ConfC
|
4
|
-
##
|
5
|
-
# Convert all raw file names to base file names.
|
6
|
-
def self.to_filenames(raw_filenames)
|
7
|
-
if raw_filenames.is_a?(Array) && !raw_filenames.empty?
|
8
|
-
raw_filenames.map do |raw_filename|
|
9
|
-
File.basename raw_filename
|
10
|
-
end
|
11
|
-
else
|
12
|
-
[]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
1
|
+
##
|
2
|
+
# ConfC
|
3
|
+
module ConfC
|
4
|
+
##
|
5
|
+
# Convert all raw file names to base file names.
|
6
|
+
def self.to_filenames(raw_filenames)
|
7
|
+
if raw_filenames.is_a?(Array) && !raw_filenames.empty?
|
8
|
+
raw_filenames.map do |raw_filename|
|
9
|
+
File.basename raw_filename
|
10
|
+
end
|
11
|
+
else
|
12
|
+
[]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/confc/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module ConfC
|
2
|
-
VERSION = '0.2.
|
3
|
-
end
|
1
|
+
module ConfC
|
2
|
+
VERSION = '0.2.1'.freeze
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Saran Tanpituckpong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,34 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 5.1.5
|
19
|
+
version: '5.2'
|
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: '5.
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 5.1.5
|
26
|
+
version: '5.2'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: mysticonfig
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.1.
|
33
|
+
version: 0.1.1
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - "~>"
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.1.
|
40
|
+
version: 0.1.1
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rainbow
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,14 +58,14 @@ dependencies:
|
|
64
58
|
requirements:
|
65
59
|
- - "~>"
|
66
60
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0.
|
61
|
+
version: 0.16.1
|
68
62
|
type: :runtime
|
69
63
|
prerelease: false
|
70
64
|
version_requirements: !ruby/object:Gem::Requirement
|
71
65
|
requirements:
|
72
66
|
- - "~>"
|
73
67
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.
|
68
|
+
version: 0.16.1
|
75
69
|
- !ruby/object:Gem::Dependency
|
76
70
|
name: aruba
|
77
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,14 +114,14 @@ dependencies:
|
|
120
114
|
requirements:
|
121
115
|
- - "~>"
|
122
116
|
- !ruby/object:Gem::Version
|
123
|
-
version: 0.
|
117
|
+
version: 0.55.0
|
124
118
|
type: :development
|
125
119
|
prerelease: false
|
126
120
|
version_requirements: !ruby/object:Gem::Requirement
|
127
121
|
requirements:
|
128
122
|
- - "~>"
|
129
123
|
- !ruby/object:Gem::Version
|
130
|
-
version: 0.
|
124
|
+
version: 0.55.0
|
131
125
|
description: Clone your default configuration files to current working directory.
|
132
126
|
email:
|
133
127
|
executables:
|
@@ -176,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
170
|
version: '0'
|
177
171
|
requirements: []
|
178
172
|
rubyforge_project:
|
179
|
-
rubygems_version: 2.7.
|
173
|
+
rubygems_version: 2.7.6
|
180
174
|
signing_key:
|
181
175
|
specification_version: 4
|
182
176
|
summary: Start new project with your default configs.
|