docker-clone 0.1.0 → 0.2.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/docker-clone +30 -1
  3. data/lib/docker_clone.rb +16 -41
  4. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6994ab4fdcd04d6eee936de0a7c914b799908dd237bc1103a9246f72f98bbb9f
4
- data.tar.gz: 66159307c9e198608c07f2cfdf64e2d3e1f29dbc471cc55a9b01a549dd631b70
3
+ metadata.gz: 634bbbc8e740e95739615acb026f969d1e27c4c6ac01ce2d63439461d84a4286
4
+ data.tar.gz: 9aac386bca973d069611c056444dce986449b710dbe2da4d00a320a568b7ac3d
5
5
  SHA512:
6
- metadata.gz: bbabdda72d504772cfb0da648daf4c84b784e7bd71fa544be6807251c3792fe2480287ca55ade94d8992da56da1603d94afcd72d7e5a61bfcda6710d8bd180a0
7
- data.tar.gz: 8b74f4893bb8a3ce5867da6af38c435c23cac98b502821b185c85c55a35f100a0be5ad13a6ac29a9318f5016cb8632a4a82668b1efd6257e3794deece39abbd2
6
+ metadata.gz: da61783c7c0b9791aa2dfff638c87639a57b489e2b7e43ea816b8f14a5fc440d2ec7206f075e8eb1434a574f2243eb3dbb545b989d18176d09e81346a8aaae33
7
+ data.tar.gz: e0c0062000344ee6788da0ecfd9bf46604aa6ecbeb91c2eb493de9072ca8afbe6282d305fb1bc451cfa63f46207e79869829a71a5b6ecf8bcd0058b464b0f95c
@@ -1,4 +1,33 @@
1
1
  #! /usr/bin/env ruby
2
2
  require "docker_clone"
3
+ require "optparse"
3
4
 
4
- DockerClone.new.clone_repos
5
+ HELP_BANNER = "Usage: docker-clone [options]"
6
+ HELP_DESCRIPTION = "Show this help message"
7
+ CONFIG_DESCRIPTION = "Path to your docker clone config file"
8
+
9
+ def parse_options
10
+ options = { config_file_path: "docker-clone.yml" }
11
+ options.tap do |options|
12
+ OptionParser.new do |parser|
13
+ parser.banner = HELP_BANNER
14
+ parser.separator ""
15
+ parser.on("-h", "--help", HELP_DESCRIPTION) do
16
+ puts parser
17
+ exit(true)
18
+ end
19
+ parser.on("-c", "--config config_file_path", CONFIG_DESCRIPTION) do |config_path|
20
+ options[:config_file_path] = config_path
21
+ end
22
+ end.parse!
23
+ end
24
+ end
25
+
26
+ def main
27
+ options = parse_options
28
+ DockerClone.new(options).clone_repos
29
+ rescue StandardError => error
30
+ puts error.message
31
+ end
32
+
33
+ main
@@ -2,25 +2,22 @@ require "yaml"
2
2
  require "optparse"
3
3
  require "pathname"
4
4
 
5
- CONFIG_DESCRIPTION = "Path to your docker pull config file"
6
- HELP_DESCRIPTION = "Show this help message"
7
-
8
- HELP_BANNER = "Usage: docker-pull [options]"
9
-
10
- DEFAULT_WORKING_DIR = "./"
5
+ DEFAULT_WORKING_DIR = "../"
11
6
 
12
7
  class NoRepoException < Exception
13
8
  end
14
9
 
15
10
  class DockerClone
16
- def initialize
11
+ def initialize(options = {})
12
+ raise ArgumentError.new("No Config File Path Given.") if !options[:config_file_path]
13
+ @config_file_path = full_path(options[:config_file_path])
14
+ @working_dir = options[:working_dir] || DEFAULT_WORKING_DIR
17
15
  get_config
18
16
  end
19
17
 
20
18
  def clone_repos
21
- working_dir = @@options[:working_dir] || DEFAULT_WORKING_DIR
22
- Dir.chdir(working_dir) do
23
- @@docker_pull["repos"].each do |repo|
19
+ Dir.chdir(@working_dir) do
20
+ @docker_clone_config["repos"].each do |repo|
24
21
  clone_repo(repo)
25
22
  end
26
23
  end
@@ -28,56 +25,34 @@ class DockerClone
28
25
 
29
26
  private
30
27
 
31
- def parse_options
32
- options = { config_path: "docker-pull.yml" }
33
- options.tap do |options|
34
- OptionParser.new do |parser|
35
- parser.banner = HELP_BANNER
36
- parser.separator ""
37
- parser.on("-h", "--help", HELP_DESCRIPTION) do
38
- puts parser
39
- exit(true)
40
- end
41
- parser.on("-c", "--config config_file_path", CONFIG_DESCRIPTION) do |config_path|
42
- options[:config_path] = config_path
43
- end
44
- end.parse!
45
- end
46
- end
47
-
48
28
  def full_path(pathname)
49
29
  path = Pathname.new(pathname)
50
30
  path.expand_path
51
31
  end
52
32
 
53
- def read_docker_file(pathname)
54
- path = full_path(pathname)
55
- file = File.read(path)
33
+ def read_docker_file
34
+ file = File.read(@config_file_path)
56
35
  YAML.load(file)
57
36
  end
58
37
 
59
- def print_docker_pull_error(path)
60
- puts "No corresponding config file, looking for #{path}"
38
+ def print_docker_clone_error(path)
39
+ raise ArgumentError.new("No corresponding config file, looking for #{path}")
61
40
  end
62
41
 
63
- def print_docker_pull_error_and_exit
64
- config_path = @@options[:config_path]
65
- full_config_path = full_path(config_path)
66
-
67
- print_docker_pull_error(full_config_path)
42
+ def print_docker_clone_error_and_exit
43
+ print_docker_clone_error(@config_file_path)
68
44
  exit(false)
69
45
  end
70
46
 
71
47
  def get_config
72
- @@options ||= parse_options
73
- @@docker_pull ||= read_docker_file(@@options[:config_path])
48
+ @docker_clone_config ||= read_docker_file
74
49
  rescue
75
- print_docker_pull_error_and_exit
50
+ print_docker_clone_error_and_exit
76
51
  end
77
52
 
78
53
  def clone_repo(repo)
79
54
  url, name = repo["url"], repo["name"]
80
- puts "No URL or name given for your repo. #{url} #{name}" if !url || !name
55
+ raise ArgumentError.new("No URL or name given for your repo. #{url} #{name}") if !url || !name
81
56
  `git clone #{url} #{name}`
82
57
  end
83
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-clone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Hivert
@@ -10,7 +10,9 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2019-03-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Get all your dockers repos
13
+ description: Docker Clone is an utility to handle the boring work of cloning all your
14
+ repos in a micro-services architecture using Docker, with a simple file definition
15
+ format.
14
16
  email: hivert.is.coming@gmail.com
15
17
  executables:
16
18
  - docker-clone
@@ -19,7 +21,7 @@ extra_rdoc_files: []
19
21
  files:
20
22
  - bin/docker-clone
21
23
  - lib/docker_clone.rb
22
- homepage:
24
+ homepage: https://github.com/ghivert/docker-clone
23
25
  licenses:
24
26
  - MIT
25
27
  metadata: {}
@@ -41,5 +43,5 @@ requirements: []
41
43
  rubygems_version: 3.0.3
42
44
  signing_key:
43
45
  specification_version: 4
44
- summary: Get all your dockers repos
46
+ summary: Clone all your Docker micro-services repos in once.
45
47
  test_files: []