gitlab-development-kit 0.2.12 → 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/gdk +101 -64
  3. data/lib/gitlab_development_kit.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fce4dd74b2f32c9cbf4519336c9b731158cb34c5570d83805fbeff74aab2c209
4
- data.tar.gz: 3b86852c3e15145a1c5c4617a05827cb4b9b7159be8c684107e0e85f57a389a2
3
+ metadata.gz: 6ea455a9185d9a48272280448034af98ee051740756dea1ed6545cec557fc957
4
+ data.tar.gz: 520cd43ae500977adade2d5bcf7d10ee09326c3ac56e8ec7a9b510ef8f0ef94b
5
5
  SHA512:
6
- metadata.gz: 245d0650689fca386f65d623fce71c5a6884b65faddd731daedb622b39fa3e7c2677218be24709bebe7d9e091dc89263fe5f8b0b4fd82e46a1beb8e125bea12a
7
- data.tar.gz: 14c63e2ab27736a16e7356f4b39b65f125949447f38cab27f90b99249a340f2ad876293b536d3d12544c6e56a380ebd15668bf8e727ccaea51fdd4a20fc2bfce
6
+ metadata.gz: 8c98398310d0c1eeda0d851dfded10ec22745e156b1550d7ad9a888eef399f37eede40f3e2a2f88963f756e2eac27fcc2af078959d27f7d93f43f92bb96c0245
7
+ data.tar.gz: 27c139a2d76cd03446c11e3c7bf0d071cfc5216ec28bb41d79faeef9e97acbc3b5ecb23a964480948f7fe0bf64622ae273a5683cfc35d344383d3947f0aefe0d
data/bin/gdk CHANGED
@@ -13,95 +13,132 @@ require 'gitlab_development_kit'
13
13
  # installed outside the gitlab-development-kit repository with 'gem
14
14
  # install'. Edit lib/gdk.rb to define new commands.
15
15
  module GDK
16
+ # TODO: Touching .gdk-install-root will be redundant shortly.
16
17
  ROOT_CHECK_FILE = '.gdk-install-root'
17
18
  DEFAULT_INIT_DIRECTORY = File.join(Dir.pwd, 'gitlab-development-kit')
18
19
 
19
- def self.launcher_main
20
- case ARGV.first
21
- when 'init'
22
- if ARGV.count > 2 || (ARGV.count == 2 && (ARGV[1] == '-help' || ARGV[1] == '--help'))
23
- puts 'Usage: gdk init [DIR]'
24
- return false
20
+ module CommandBasic
21
+ class Main
22
+ def initialize(args)
23
+ @args = args
25
24
  end
26
25
 
27
- directory = ARGV.count == 2 ? ARGV[1] : DEFAULT_INIT_DIRECTORY
28
- if directory.start_with?('-')
29
- warn <<~INVALID_GDK_DIR_NAME
30
- The gdk directory cannot start with a dash ('-'). Did you mean:
31
- gdk init #{directory.sub(/^-+/, '')}
32
- INVALID_GDK_DIR_NAME
33
- return false
26
+ def run
27
+ return GDK::CommandBasic::Version.new.run if gdk_version?
28
+ return GDK::CommandBasic::Init.new(args[1..]).run if gdk_init?
29
+
30
+ if gdk_dir?
31
+ require(File.join(gdk_root, 'lib/gdk.rb'))
32
+ GDK.main
33
+ else
34
+ warn_not_gdk_dir
35
+ false
36
+ end
34
37
  end
35
38
 
36
- cmd = %W[git clone https://gitlab.com/gitlab-org/gitlab-development-kit.git #{directory}]
37
- system(*cmd) && remember!(directory)
38
- else
39
- if print_version?
40
- puts VERSION
39
+ private
41
40
 
42
- return true
41
+ attr_reader :args
42
+
43
+ def warn_not_gdk_dir
44
+ warn <<~NOT_A_GDK_DIR
45
+
46
+ The current working directory is not inside a gitlab-development-kit
47
+ installation. Use 'cd' to go to your gitlab-development-kit or create
48
+ a new one with 'gdk init'.
49
+
50
+ gdk init [DIRECTORY] # Default: #{DEFAULT_INIT_DIRECTORY}
51
+
52
+ NOT_A_GDK_DIR
43
53
  end
44
54
 
45
- unless gdk_dir?
46
- warn_not_gdk_dir
55
+ def gdk_root
56
+ @gdk_root ||= find_root(Dir.pwd)
57
+ end
58
+
59
+ def gdk_dir?
60
+ !gdk_root.nil?
61
+ end
47
62
 
48
- return false
63
+ def gdk_version?
64
+ # If gdk_dir? == true, fall through to allow lib/gdk.rb to handle
65
+ %w[version --version].include?(args.first) && !gdk_dir?
49
66
  end
50
67
 
51
- load(File.join(gdk_root, 'lib/gdk.rb'))
52
- GDK.main
68
+ def gdk_init?
69
+ args.first == 'init'
70
+ end
71
+
72
+ def find_root(current)
73
+ if File.exist?(File.join(current, 'GDK_ROOT'))
74
+ File.realpath(current)
75
+ elsif File.realpath(current) == '/'
76
+ nil
77
+ else
78
+ find_root(File.join(current, '..'))
79
+ end
80
+ end
53
81
  end
54
- end
55
82
 
56
- def self.warn_not_gdk_dir
57
- warn <<~NOT_A_GDK_DIR
83
+ class Version
84
+ def run
85
+ puts GDK::VERSION
86
+ true
87
+ end
88
+ end
58
89
 
59
- The current working directory is not inside a gitlab-development-kit
60
- installation. Use 'cd' to go to your gitlab-development-kit or create
61
- a new one with 'gdk init'.
90
+ class Init
91
+ def initialize(args)
92
+ @args = args
93
+ end
62
94
 
63
- gdk init [DIRECTORY] # Default: #{DEFAULT_INIT_DIRECTORY}
95
+ def run
96
+ warn("INFO: 'gdk init' is deprecated and will be removed in a future update.")
64
97
 
65
- NOT_A_GDK_DIR
66
- end
98
+ if show_help?
99
+ puts('Usage: gdk init [DIR]')
67
100
 
68
- def self.gdk_root
69
- @gdk_root ||= find_root(Dir.pwd)
70
- end
101
+ return true
102
+ end
71
103
 
72
- def self.gdk_dir?
73
- !gdk_root.nil?
74
- end
104
+ directory = new_gdk_directory
105
+ if new_gdk_directory_invalid?(directory)
106
+ warn("ERROR: The proposed new GDK directory '#{directory}' is invalid because it begins with a dash.")
75
107
 
76
- def self.print_version?
77
- %w[version --version].include?(ARGV.first) && !gdk_dir?
78
- end
108
+ return false
109
+ end
79
110
 
80
- def self.find_root(current)
81
- if File.exist?(File.join(current, 'GDK_ROOT'))
82
- File.realpath(current)
83
- elsif File.realpath(current) == '/'
84
- nil
85
- else
86
- find_root(File.join(current, '..'))
87
- end
88
- end
111
+ if clone_gdk(directory)
112
+ puts("INFO: Successfully git cloned the GDK into '#{directory}'.")
113
+ true
114
+ else
115
+ warn("ERROR: An error occurred while attempting to git clone the GDK into '#{directory}'.")
116
+ false
117
+ end
118
+ end
89
119
 
90
- def self.load_dotfile
91
- File.open(DOTFILE, File::RDONLY | File::CREAT) do |f|
92
- YAML.safe_load(f)
93
- end || {}
94
- end
120
+ private
121
+
122
+ attr_reader :args
95
123
 
96
- def self.remember!(directory)
97
- File.open("#{directory}/#{ROOT_CHECK_FILE}", 'w') do |f|
98
- f.puts File.realpath(directory)
124
+ def show_help?
125
+ args.count > 1 || (args & %w[-help --help]).any?
126
+ end
127
+
128
+ def new_gdk_directory_invalid?(directory)
129
+ directory.start_with?('-')
130
+ end
131
+
132
+ def new_gdk_directory
133
+ args.count == 1 ? args.first : GDK::DEFAULT_INIT_DIRECTORY
134
+ end
135
+
136
+ def clone_gdk(directory)
137
+ cmd = "git clone https://gitlab.com/gitlab-org/gitlab-development-kit.git #{directory}"
138
+ system(*cmd)
139
+ end
99
140
  end
100
- true
101
- rescue StandardError => e
102
- warn e
103
- false
104
141
  end
105
142
  end
106
143
 
107
- exit(GDK.launcher_main)
144
+ exit(GDK::CommandBasic::Main.new(ARGV).run)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GDK
4
- GEM_VERSION = '0.2.12'
4
+ GEM_VERSION = '0.2.14'
5
5
  VERSION = "GitLab Development Kit #{GEM_VERSION}"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-development-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Vosmaer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-04-23 00:00:00.000000000 Z
12
+ date: 2021-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake