gem-clone 0.2.0 → 0.4.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: cf92769fcccbfc24afb0301081e3c935d02b47d1136b4afebd9ffc8c61f4564c
4
- data.tar.gz: db3c451de56900a6629346e40168bbb7914c1c45005215012646a5e3842b3011
3
+ metadata.gz: 2f12bc26161d323018bdf18116360bb9b81981044ed51c1d451a4db2cc103b32
4
+ data.tar.gz: 0aea0c5003456030440a5b0a74982cb13813731594a35933a19f9a68d13c2c33
5
5
  SHA512:
6
- metadata.gz: 9bc582e2011a9396d1c47c5cad7da4705b068b650bf482c017104e19c412eb5953e98f8e84e2db110ec0aa3a9c0dc0b50af220deb718a5b733c4d80d338a05d5
7
- data.tar.gz: 60186bc4c5e5420bfe8cf585c7edf2ce43aa1692c63c7deafbda4aac6224181918a99d6f2c35e6b2f4e74db89fcb467cfa1ea302aa074ef8c11412699658f194
6
+ metadata.gz: 537472ed15d28e45ef000fa04e2679a6f84ed5ce10df8c66f5ca6353a68bf172c289d5ec3b60033e640592e1029a73e90201771e4b749a7efb81905ad2edbc08
7
+ data.tar.gz: 92aef3618b93a10f46845f101b905bea041d8b6ee4628a710747a455c2f12ae264edbecc756cb89d93b368719aaaeb93b6ae4a638b375cc1285690b862442adc
data/README.md CHANGED
@@ -17,7 +17,9 @@ gem install rubygems-clone-0.1.0.gem
17
17
 
18
18
  ## Prerequisites
19
19
 
20
- This plugin requires `ghq` to be installed and available in your PATH.
20
+ This plugin works best with `ghq` but will automatically fall back to `git clone` if `ghq` is not available.
21
+
22
+ ### Recommended: Install ghq
21
23
 
22
24
  ```bash
23
25
  # Install ghq (example for macOS)
@@ -27,6 +29,10 @@ brew install ghq
27
29
  go install github.com/x-motemen/ghq@latest
28
30
  ```
29
31
 
32
+ ### Fallback: Git only
33
+
34
+ If `ghq` is not installed, the plugin will automatically use `git clone` instead. Make sure `git` is available in your PATH.
35
+
30
36
  ## Usage
31
37
 
32
38
  ```bash
@@ -35,6 +41,9 @@ gem clone sinatra
35
41
 
36
42
  # Clone with verbose output
37
43
  gem clone rails --verbose
44
+
45
+ # Show repository URL without cloning
46
+ gem clone rails --show-url
38
47
  ```
39
48
 
40
49
  The command will:
@@ -44,20 +53,42 @@ The command will:
44
53
  - `source_code_uri` metadata
45
54
  - `homepage_uri` (if it looks like a repository URL)
46
55
  - `project_uri` (if it looks like a repository URL)
47
- 3. Use `ghq get` to clone the repository
56
+ 3. Clone the repository using:
57
+ - `ghq get` (preferred method if available)
58
+ - `git clone` (fallback if ghq is not available)
59
+ - Skip cloning if `--show-url` is specified
60
+
61
+ ## Options
62
+
63
+ - `-v, --verbose`: Show verbose output during execution
64
+ - `-u, --show-url`: Display the repository URL without executing the clone operation
48
65
 
49
66
  ## Examples
50
67
 
51
68
  ```bash
69
+ # With ghq available
52
70
  $ gem clone sinatra
53
71
  Executing: ghq get https://github.com/sinatra/sinatra
54
72
  Successfully cloned repository: https://github.com/sinatra/sinatra
55
73
 
74
+ # With verbose output
56
75
  $ gem clone rails --verbose
57
76
  Fetching gem metadata for 'rails'...
58
77
  Found repository URL: https://github.com/rails/rails
59
78
  Executing: ghq get https://github.com/rails/rails
60
79
  Successfully cloned repository: https://github.com/rails/rails
80
+
81
+ # Fallback to git clone when ghq is not available
82
+ $ gem clone rails --verbose
83
+ Fetching gem metadata for 'rails'...
84
+ Found repository URL: https://github.com/rails/rails
85
+ ghq not found, falling back to git clone
86
+ Executing: git clone https://github.com/rails/rails
87
+ Successfully cloned repository: https://github.com/rails/rails
88
+
89
+ # Show URL only
90
+ $ gem clone rails --show-url
91
+ https://github.com/rails/rails
61
92
  ```
62
93
 
63
94
  ## Development
@@ -1,5 +1,4 @@
1
1
  require 'rubygems/command'
2
- require 'rubygems/remote_fetcher'
3
2
  require 'json'
4
3
  require 'net/http'
5
4
  require 'uri'
@@ -9,7 +8,11 @@ class Gem::Commands::CloneCommand < Gem::Command
9
8
  super 'clone', 'Clone a gem repository using ghq'
10
9
 
11
10
  add_option('-v', '--verbose', 'Show verbose output') do |value, options|
12
- options[:verbose] = value
11
+ options[:verbose] = true
12
+ end
13
+
14
+ add_option('-u', '--show-url', 'Show repository URL without cloning') do |value, options|
15
+ options[:show_url] = true
13
16
  end
14
17
  end
15
18
 
@@ -26,6 +29,7 @@ source_code_uri from the gem's metadata.
26
29
  Examples:
27
30
  gem clone sinatra
28
31
  gem clone rails --verbose
32
+ gem clone rails --show-url
29
33
  EOF
30
34
  end
31
35
 
@@ -50,7 +54,11 @@ Examples:
50
54
 
51
55
  say "Found repository URL: #{repository_url}" if options[:verbose]
52
56
 
53
- clone_repository(repository_url)
57
+ if options[:show_url]
58
+ say repository_url
59
+ else
60
+ clone_repository(repository_url)
61
+ end
54
62
  end
55
63
 
56
64
  private
@@ -99,6 +107,23 @@ Examples:
99
107
  end
100
108
 
101
109
  def clone_repository(url)
110
+ if command_available?('ghq')
111
+ clone_with_ghq(url)
112
+ elsif command_available?('git')
113
+ clone_with_git(url)
114
+ else
115
+ alert_error "Neither 'ghq' nor 'git' is available in your PATH. Please install one of them."
116
+ terminate_interaction 1
117
+ end
118
+ end
119
+
120
+ private
121
+
122
+ def command_available?(command)
123
+ system("which #{command} > /dev/null 2>&1")
124
+ end
125
+
126
+ def clone_with_ghq(url)
102
127
  command = "ghq get #{url}"
103
128
  say "Executing: #{command}" if options[:verbose]
104
129
 
@@ -107,7 +132,22 @@ Examples:
107
132
  if $?.success?
108
133
  say "Successfully cloned repository: #{url}"
109
134
  else
110
- alert_error "Failed to clone repository. Make sure 'ghq' is installed and available in your PATH."
135
+ alert_error "Failed to clone repository with ghq."
136
+ terminate_interaction 1
137
+ end
138
+ end
139
+
140
+ def clone_with_git(url)
141
+ command = "git clone #{url}"
142
+ say "ghq not found, falling back to git clone" if options[:verbose]
143
+ say "Executing: #{command}" if options[:verbose]
144
+
145
+ system(command)
146
+
147
+ if $?.success?
148
+ say "Successfully cloned repository: #{url}"
149
+ else
150
+ alert_error "Failed to clone repository with git."
111
151
  terminate_interaction 1
112
152
  end
113
153
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-clone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi SHIBATA
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  - !ruby/object:Gem::Version
38
38
  version: '0'
39
39
  requirements: []
40
- rubygems_version: 3.7.0.dev
40
+ rubygems_version: 3.6.7
41
41
  specification_version: 4
42
42
  summary: A RubyGems plugin to clone gem repositories
43
43
  test_files: []