jive 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/jive.sh +2 -2
- data/lib/jive.rb +2 -0
- data/lib/jive/cli.rb +12 -37
- data/lib/jive/git.rb +40 -0
- data/lib/jive/shell.rb +45 -0
- data/lib/jive/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecf28e3a1d722522cb6fc2bb810c34563ba78f81209f78f8a4abc7e628c6f23e
|
4
|
+
data.tar.gz: 9c8c3e0390939c7393b7cc170d538f3f1a97595d8c4b8783dac66cd000067ecd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1631fb5229c44e2ab09e3c38723e7db97822a3c7fa0525220b9f901b38d8ee1a6f7e19e2c9d138bab405edb7ec1d4c7c210020e18c3092fc76577b867db9f73
|
7
|
+
data.tar.gz: 842ac071b5edf167f5c9c240faf4466cbee6979bdfa797fed89e60f4db852486da68ae2d8e1186e8d4229af69e671e08a0b2716a4435f0eea96dd25b47d4b62d
|
data/jive.sh
CHANGED
@@ -43,7 +43,7 @@ __jive_open_pipe() {
|
|
43
43
|
local tmpfile
|
44
44
|
tmpfile="$(\mktemp -u)"
|
45
45
|
|
46
|
-
exec
|
46
|
+
exec 42>"${tmpfile}" # Open the tempfile for writing on FD 42.
|
47
47
|
exec 8<"${tmpfile}" # Open the tempfile for reading on FD 8.
|
48
48
|
\rm -f "${tmpfile}" # Unlink the tempfile. (we've already opened it).
|
49
49
|
}
|
@@ -76,7 +76,7 @@ __jive_flush_tasks() {
|
|
76
76
|
|
77
77
|
__jive_close_pipe() {
|
78
78
|
exec 8<&- # close FD 8.
|
79
|
-
exec
|
79
|
+
exec 42<&- # close FD 42.
|
80
80
|
}
|
81
81
|
|
82
82
|
jive() {
|
data/lib/jive.rb
CHANGED
data/lib/jive/cli.rb
CHANGED
@@ -11,17 +11,18 @@ module Jive
|
|
11
11
|
true
|
12
12
|
end
|
13
13
|
|
14
|
+
desc "cd <org>/<project>", "cd to ~/src/github.com/<org>/<project>"
|
15
|
+
def cd(slug)
|
16
|
+
runner.run_safely do
|
17
|
+
Git.new(runner).cd(slug)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
14
21
|
desc "clone <org>/<project>", "git clone to ~/src/github.com/<org>/<project>"
|
15
22
|
def clone(slug)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
[:git, "clone", "git@github.com:#{slug}.git", target_dir]
|
20
|
-
])
|
21
|
-
after_run([
|
22
|
-
["cd", target_dir],
|
23
|
-
["setenv", "JIVE_LAST_RUN=#{Time.now.to_i}"]
|
24
|
-
])
|
23
|
+
runner.run_safely do
|
24
|
+
Git.new(runner).clone(slug)
|
25
|
+
end
|
25
26
|
end
|
26
27
|
|
27
28
|
desc "setup", "provide instructions to integrate into shell"
|
@@ -35,34 +36,8 @@ module Jive
|
|
35
36
|
|
36
37
|
private
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
echo: "/usr/bin/echo",
|
41
|
-
git: "/usr/bin/git",
|
42
|
-
mkdir: "/usr/bin/mkdir"
|
43
|
-
}.freeze
|
44
|
-
|
45
|
-
def run_each(tasks)
|
46
|
-
tasks.each do |task|
|
47
|
-
break unless execute(task)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def execute(command, env: {})
|
52
|
-
system(env, expand(command))
|
53
|
-
end
|
54
|
-
|
55
|
-
def after_run(tasks)
|
56
|
-
finalizer_fd = 9
|
57
|
-
pipe = IO.new(finalizer_fd)
|
58
|
-
pipe.puts(tasks.map { |x| x.join(":") }.join("\n"))
|
59
|
-
end
|
60
|
-
|
61
|
-
def expand(command)
|
62
|
-
Array(command)
|
63
|
-
.flatten
|
64
|
-
.map { |x| COMMAND_MAP.fetch(x, x).to_s }
|
65
|
-
.join(" ")
|
39
|
+
def runner
|
40
|
+
@runner ||= ::Jive::Shell.new
|
66
41
|
end
|
67
42
|
end
|
68
43
|
end
|
data/lib/jive/git.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jive
|
4
|
+
class Git
|
5
|
+
attr_reader :shell
|
6
|
+
|
7
|
+
def initialize(shell)
|
8
|
+
@shell = shell
|
9
|
+
end
|
10
|
+
|
11
|
+
def clone(slug)
|
12
|
+
dir = target_dir_for(slug)
|
13
|
+
unless dir.exist?
|
14
|
+
shell.run_each([
|
15
|
+
[:mkdir, "-p", dir.parent.to_s],
|
16
|
+
[:git, "clone", "git@github.com:#{slug}.git", dir]
|
17
|
+
])
|
18
|
+
end
|
19
|
+
cd(slug)
|
20
|
+
end
|
21
|
+
|
22
|
+
def cd(slug)
|
23
|
+
dir = target_dir_for(slug)
|
24
|
+
if dir.exist?
|
25
|
+
shell.after_run([
|
26
|
+
["cd", dir],
|
27
|
+
["setenv", "JIVE_LAST_RUN=#{Time.now.to_i}"]
|
28
|
+
])
|
29
|
+
else
|
30
|
+
clone(slug)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def target_dir_for(slug)
|
37
|
+
Pathname.new(Dir.home).join("src/github.com/#{slug}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/jive/shell.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jive
|
4
|
+
class Shell
|
5
|
+
COMMAND_MAP = {
|
6
|
+
cd: "/usr/bin/cd",
|
7
|
+
echo: "/usr/bin/echo",
|
8
|
+
git: "/usr/bin/git",
|
9
|
+
mkdir: "/usr/bin/mkdir"
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
def run_each(tasks)
|
13
|
+
tasks.each do |task|
|
14
|
+
break unless execute(task)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute(command, env: {})
|
19
|
+
system(env, expand(command))
|
20
|
+
end
|
21
|
+
|
22
|
+
def after_run(tasks)
|
23
|
+
finalizer_fd = 42
|
24
|
+
pipe = IO.new(finalizer_fd)
|
25
|
+
pipe.puts(tasks.map { |x| x.join(":") }.join("\n"))
|
26
|
+
rescue Errno::EBADF => e
|
27
|
+
puts e
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
|
31
|
+
def expand(command)
|
32
|
+
Array(command)
|
33
|
+
.flatten
|
34
|
+
.map { |x| COMMAND_MAP.fetch(x, x).to_s }
|
35
|
+
.join(" ")
|
36
|
+
end
|
37
|
+
|
38
|
+
def run_safely
|
39
|
+
yield
|
40
|
+
rescue StandardError => e
|
41
|
+
puts e
|
42
|
+
after_run([%w[noop noop]])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/jive/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mo khan
|
@@ -110,8 +110,10 @@ files:
|
|
110
110
|
- lib/jive.rb
|
111
111
|
- lib/jive/batch_runner.rb
|
112
112
|
- lib/jive/cli.rb
|
113
|
+
- lib/jive/git.rb
|
113
114
|
- lib/jive/popen.rb
|
114
115
|
- lib/jive/runner.rb
|
116
|
+
- lib/jive/shell.rb
|
115
117
|
- lib/jive/version.rb
|
116
118
|
homepage: https://rubygems.org/gems/jive
|
117
119
|
licenses:
|