dep 1.0.9 → 1.1.0

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/dep +30 -28
  3. data/test/dep.rb +30 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e524ea44c406b91aee8bd1dd52818bc1cbd9a4d9
4
- data.tar.gz: 95272d72184f135265f22263f1eb773b72431fd8
3
+ metadata.gz: 76ef3eef686b0b32799b211eb23c2db50914be15
4
+ data.tar.gz: 16636d764be0bccd03082d56daa57ed7d6cebc74
5
5
  SHA512:
6
- metadata.gz: 188c63e82626083d79b8e230141cc6a80813009e3b3fe06eab692dd69fc579d73f21677f88098e1d707b53b39c48b4f08eda761b3c23f7932c0dc08fa94bc9ea
7
- data.tar.gz: 65e035c49b90bc187f3a4b8cac9b711d94971b90828f56d58d95543faca01843c9fbdc9bcb339aad139764f6bdc2b3ae0b835b38c56f1c1b13396fe3b902d244
6
+ metadata.gz: 1284025521df66b6024f5d87b205fc43bc9376c2f364ee83b91ed9990098c98a7ece86168a998fa8f263407be0c5a31b74138095ffcc2964cf9ce27d4b249720
7
+ data.tar.gz: 382c097dd64b1ffe800590c46b46c6030f89f2fd905d808d917bac2c83f82e72494eff287a058ebf56a28ec91bf0d21301532354bc3d03e03a75e07b9e32fb62
data/bin/dep CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  require "fileutils"
4
4
 
5
+ def die
6
+ abort("error: dep --help for more info")
7
+ end
8
+
5
9
  module Dep
6
10
  class List
7
11
  attr :path
@@ -55,17 +59,19 @@ module Dep
55
59
  "#{name} -v #{version}"
56
60
  end
57
61
 
62
+ def csv
63
+ "#{name}:#{version}"
64
+ end
65
+
58
66
  def ==(other)
59
67
  to_s == other.to_s
60
68
  end
61
69
  end
62
70
 
63
- module CLI
64
- class << self
65
- attr_accessor :prerelease, :list, :file
66
- end
71
+ class CLI
72
+ attr_accessor :prerelease, :list, :file
67
73
 
68
- def self.add(name)
74
+ def add(name)
69
75
  dependency = Gem::Dependency.new(name)
70
76
  fetcher = Gem::SpecFetcher.fetcher
71
77
 
@@ -87,14 +93,14 @@ module Dep
87
93
  puts "dep: added #{lib}"
88
94
  end
89
95
 
90
- def self.rm(name)
96
+ def rm(name)
91
97
  @list.remove(Dep::Lib.new(name))
92
98
  @list.save
93
99
 
94
100
  puts "dep: removed #{name}"
95
101
  end
96
102
 
97
- def self.check
103
+ def check
98
104
  if @list.missing_libraries.empty?
99
105
  puts "dep: all cool"
100
106
  else
@@ -108,25 +114,19 @@ module Dep
108
114
  end
109
115
  end
110
116
 
111
- def self.install
117
+ def install
112
118
  if @list.missing_libraries.empty?
113
119
  puts "dep: nothing to install"
114
120
  exit
115
121
  end
116
122
 
117
- @list.missing_libraries.each do |lib|
118
- run "gem install #{lib}"
119
- end
123
+ run "gem install #{@list.missing_libraries.map(&:csv).join(" ")}"
120
124
  end
121
125
 
122
- def self.run(cmd)
126
+ def run(cmd)
123
127
  puts " #{cmd}"
124
128
  `#{cmd}`
125
129
  end
126
-
127
- def self.abort
128
- abort("error: dep --help for more info")
129
- end
130
130
  end
131
131
  end
132
132
 
@@ -140,7 +140,7 @@ private
140
140
  when 1 then block.call(ARGV.delete_at(index))
141
141
  when 0 then block.call
142
142
  else
143
- Dep::CLI.abort
143
+ die
144
144
  end
145
145
  end
146
146
  end
@@ -151,15 +151,17 @@ end
151
151
  # script, we have to instead rely on a different condition.
152
152
  if File.basename($0) == "dep"
153
153
 
154
- Dep::CLI.file = File.join(Dir.pwd, ".gems")
155
- Dep::CLI.prerelease = false
154
+ cli = Dep::CLI.new
155
+
156
+ cli.file = File.join(Dir.pwd, ".gems")
157
+ cli.prerelease = false
156
158
 
157
159
  on("-f") do |file|
158
- Dep::CLI.file = file
160
+ cli.file = file
159
161
  end
160
162
 
161
163
  on("--pre") do
162
- Dep::CLI.prerelease = true
164
+ cli.prerelease = true
163
165
  end
164
166
 
165
167
  on("--help") do
@@ -171,21 +173,21 @@ if File.basename($0) == "dep"
171
173
  exit
172
174
  end
173
175
 
174
- Dep::CLI.list = Dep::List.new(Dep::CLI.file)
176
+ cli.list = Dep::List.new(cli.file)
175
177
 
176
- FileUtils.touch(Dep::CLI.list.path) unless File.exist?(Dep::CLI.list.path)
178
+ FileUtils.touch(cli.list.path) unless File.exist?(cli.list.path)
177
179
 
178
180
  case ARGV[0]
179
181
  when "add"
180
- Dep::CLI.add(ARGV[1])
182
+ cli.add(ARGV[1])
181
183
  when "rm"
182
- Dep::CLI.rm(ARGV[1])
184
+ cli.rm(ARGV[1])
183
185
  when "install", "i"
184
- Dep::CLI.install
186
+ cli.install
185
187
  when nil
186
- Dep::CLI.check
188
+ cli.check
187
189
  else
188
- Dep::CLI.abort
190
+ die
189
191
  end
190
192
 
191
193
  end
@@ -1,7 +1,12 @@
1
1
  require "cutest"
2
+ require "override"
2
3
 
3
4
  load File.expand_path("../../bin/dep", __FILE__)
4
5
 
6
+ class Cutest::Scope
7
+ include Override
8
+ end
9
+
5
10
  # Dep::Lib
6
11
  scope do
7
12
  test "parsing" do
@@ -51,3 +56,28 @@ scope do
51
56
  assert list.libraries.include?(Dep::Lib.new("cutest", "2.0"))
52
57
  end
53
58
  end
59
+
60
+ # Dep::CLI
61
+ scope do
62
+ setup do
63
+ list = Dep::List.new("/dev/null")
64
+
65
+ list.add(Dep::Lib.new("foo", "2.0"))
66
+ list.add(Dep::Lib.new("bar", "1.1"))
67
+
68
+ commands = []
69
+
70
+ cli = Dep::CLI.new
71
+ cli.list = list
72
+
73
+ override(cli, run: -> args { commands << args })
74
+
75
+ [cli, commands]
76
+ end
77
+
78
+ test "install" do |cli, commands|
79
+ cli.install
80
+
81
+ assert_equal ["gem install foo:2.0 bar:1.1"], commands
82
+ end
83
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dep
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril David