oleg 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/leg/commands/base_command.rb +1 -23
- data/lib/leg/commands/repo.rb +62 -0
- data/lib/leg/commands/unrepo.rb +47 -0
- data/lib/leg/commands.rb +2 -9
- data/lib/leg.rb +1 -0
- metadata +19 -12
- data/lib/leg/commands/build.rb +0 -19
- data/lib/leg/commands/clean.rb +0 -19
- data/lib/leg/commands/contract.rb +0 -14
- data/lib/leg/commands/diff.rb +0 -22
- data/lib/leg/commands/edit.rb +0 -34
- data/lib/leg/commands/expand.rb +0 -14
- data/lib/leg/commands/ls.rb +0 -16
- data/lib/leg/commands/next.rb +0 -21
- data/lib/leg/commands/run.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ac8cee4dad8a55e94651eb2d33edd53cea75916
|
4
|
+
data.tar.gz: 84e8815155601c9aae38aef137118b32566b1eed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cdf3ddf88c6ba1d8a45cd97eaadf9ec5e915e615789ffbbcd578f2f0fe8435ad27a29a4a8957ef902128968e6efeec5e2322f57eea92ab9b7e0759af1227b04
|
7
|
+
data.tar.gz: 94b7d9b06b895d56075c3fb31249b713ca6445961f95f78b3818af9ca624632a79ecdf5eda99185f951f79c3731e08cdfd847e0200c578ddce7e6daee3941c71
|
@@ -14,10 +14,6 @@ class Leg::Commands::BaseCommand
|
|
14
14
|
|
15
15
|
ERROR_MSG = {
|
16
16
|
config: "You are not in a leg working directory.",
|
17
|
-
config_build: "Config file doesn't have build instructions.",
|
18
|
-
config_run: "Config file doesn't have run instructions.",
|
19
|
-
config_clean: "Config file doesn't have cleaning instructions.",
|
20
|
-
config_editor: "Config file doesn't specify a text editor."
|
21
17
|
}
|
22
18
|
|
23
19
|
def needs!(what)
|
@@ -26,14 +22,6 @@ class Leg::Commands::BaseCommand
|
|
26
22
|
case what
|
27
23
|
when :config
|
28
24
|
valid = true if @config
|
29
|
-
when :config_build
|
30
|
-
valid = true if @config[:build]
|
31
|
-
when :config_run
|
32
|
-
valid = true if @config[:run]
|
33
|
-
when :config_clean
|
34
|
-
valid = true if @config[:clean]
|
35
|
-
when :config_editor
|
36
|
-
valid = true if @config[:editor]
|
37
25
|
else
|
38
26
|
raise NotImplementedError
|
39
27
|
end
|
@@ -44,20 +32,10 @@ class Leg::Commands::BaseCommand
|
|
44
32
|
end
|
45
33
|
end
|
46
34
|
|
47
|
-
def shell_command(*cmd, exec: false, echo: true, exit_on_failure: true)
|
48
|
-
if exec
|
49
|
-
exec(*cmd)
|
50
|
-
else
|
51
|
-
puts cmd if echo
|
52
|
-
success = system(*cmd)
|
53
|
-
exit! if !success && exit_on_failure
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
35
|
def steps
|
58
36
|
@steps ||= Dir[File.join(@config[:path], "*")].map do |f|
|
59
37
|
name = File.basename(f)
|
60
|
-
name if File.directory?(f) && name =~ /\A\d+(\.\d+)*\z/
|
38
|
+
name if File.directory?(f) && name =~ /\A\d+(\.\d+)*(-\w+)*\z/
|
61
39
|
end.compact.sort_by { |s| s.split(".").map(&:to_i) }
|
62
40
|
end
|
63
41
|
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class Leg::Commands::Repo < Leg::Commands::BaseCommand
|
2
|
+
def self.name
|
3
|
+
"repo"
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.summary
|
7
|
+
"Convert step folders into a version controlled repository"
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
needs! :config
|
12
|
+
|
13
|
+
FileUtils.cd(@config[:path])
|
14
|
+
|
15
|
+
if File.exist?("repo")
|
16
|
+
puts "Error: A repo already exists!"
|
17
|
+
exit!
|
18
|
+
end
|
19
|
+
|
20
|
+
FileUtils.mkdir("repo")
|
21
|
+
repo = Rugged::Repository.init_at("repo")
|
22
|
+
|
23
|
+
steps.each do |step|
|
24
|
+
index = repo.index
|
25
|
+
index.read_tree(repo.head.target.tree) unless repo.empty?
|
26
|
+
|
27
|
+
FileUtils.cd(step_path(step)) do
|
28
|
+
Dir["**/*"].each do |path|
|
29
|
+
unless File.directory?(path)
|
30
|
+
oid = repo.write(File.read(path), :blob)
|
31
|
+
index.add(path: path, oid: oid, mode: 0100644)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
options = {}
|
37
|
+
options[:tree] = index.write_tree(repo)
|
38
|
+
options[:message] = step
|
39
|
+
options[:parents] = repo.empty? ? [] : [repo.head.target]
|
40
|
+
options[:update_ref] = 'HEAD'
|
41
|
+
|
42
|
+
commit_oid = Rugged::Commit.create(repo, options)
|
43
|
+
|
44
|
+
tags = []
|
45
|
+
if idx = step.index('-')
|
46
|
+
tags << step[0...idx]
|
47
|
+
tags << step[(idx+1)..-1]
|
48
|
+
else
|
49
|
+
tags << step
|
50
|
+
end
|
51
|
+
|
52
|
+
tags.each do |tag|
|
53
|
+
repo.references.create("refs/tags/#{tag}", commit_oid)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
repo.checkout_head(strategy: :force)
|
58
|
+
|
59
|
+
FileUtils.rm_r(steps)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Leg::Commands::Unrepo < Leg::Commands::BaseCommand
|
2
|
+
def self.name
|
3
|
+
"unrepo"
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.summary
|
7
|
+
"Convert repository into step folders"
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
needs! :config
|
12
|
+
|
13
|
+
FileUtils.cd(@config[:path])
|
14
|
+
|
15
|
+
if !File.exist?("repo")
|
16
|
+
puts "Error: repo folder doesn't exist!"
|
17
|
+
exit!
|
18
|
+
end
|
19
|
+
|
20
|
+
repo = Rugged::Repository.new("repo")
|
21
|
+
|
22
|
+
tag_names = {}
|
23
|
+
repo.tags.each do |tag|
|
24
|
+
if tag.name !~ /\A\d+(\.\d+)*\z/
|
25
|
+
tag_names[tag.target.oid] = tag.name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
walker = Rugged::Walker.new(repo)
|
30
|
+
walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
|
31
|
+
walker.push(repo.branches.find { |b| b.name == "master" }.target)
|
32
|
+
walker.each.with_index do |commit, idx|
|
33
|
+
step = (idx + 1).to_s
|
34
|
+
step_name = step
|
35
|
+
if tag_name = tag_names[commit.oid]
|
36
|
+
step_name += "-#{tag_name}"
|
37
|
+
end
|
38
|
+
|
39
|
+
step_path = File.join(@config[:path], step_name)
|
40
|
+
|
41
|
+
repo.checkout(commit.oid, strategy: :force, target_directory: step_path)
|
42
|
+
end
|
43
|
+
|
44
|
+
FileUtils.rm_r("repo")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
data/lib/leg/commands.rb
CHANGED
@@ -4,15 +4,8 @@ end
|
|
4
4
|
|
5
5
|
require 'leg/commands/base_command'
|
6
6
|
|
7
|
-
require 'leg/commands/build'
|
8
|
-
require 'leg/commands/clean'
|
9
|
-
require 'leg/commands/contract'
|
10
|
-
require 'leg/commands/diff'
|
11
|
-
require 'leg/commands/edit'
|
12
|
-
require 'leg/commands/expand'
|
13
7
|
require 'leg/commands/help'
|
14
|
-
require 'leg/commands/ls'
|
15
|
-
require 'leg/commands/next'
|
16
8
|
require 'leg/commands/pieces'
|
17
|
-
require 'leg/commands/
|
9
|
+
require 'leg/commands/repo'
|
10
|
+
require 'leg/commands/unrepo'
|
18
11
|
|
data/lib/leg.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oleg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Ruten
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
12
|
-
dependencies:
|
11
|
+
date: 2017-03-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rugged
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.25.1.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.25.1.1
|
13
27
|
description:
|
14
28
|
email: jeremy.ruten@gmail.com
|
15
29
|
executables:
|
@@ -22,17 +36,10 @@ files:
|
|
22
36
|
- lib/leg/cli.rb
|
23
37
|
- lib/leg/commands.rb
|
24
38
|
- lib/leg/commands/base_command.rb
|
25
|
-
- lib/leg/commands/build.rb
|
26
|
-
- lib/leg/commands/clean.rb
|
27
|
-
- lib/leg/commands/contract.rb
|
28
|
-
- lib/leg/commands/diff.rb
|
29
|
-
- lib/leg/commands/edit.rb
|
30
|
-
- lib/leg/commands/expand.rb
|
31
39
|
- lib/leg/commands/help.rb
|
32
|
-
- lib/leg/commands/ls.rb
|
33
|
-
- lib/leg/commands/next.rb
|
34
40
|
- lib/leg/commands/pieces.rb
|
35
|
-
- lib/leg/commands/
|
41
|
+
- lib/leg/commands/repo.rb
|
42
|
+
- lib/leg/commands/unrepo.rb
|
36
43
|
homepage: https://github.com/yjerem/leg
|
37
44
|
licenses:
|
38
45
|
- MIT
|
data/lib/leg/commands/build.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
class Leg::Commands::Build < Leg::Commands::BaseCommand
|
2
|
-
def self.name
|
3
|
-
"build"
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.summary
|
7
|
-
"Build a version (latest by default) of a project"
|
8
|
-
end
|
9
|
-
|
10
|
-
def run
|
11
|
-
needs! :config
|
12
|
-
needs! :config_build
|
13
|
-
|
14
|
-
select_step(current_or_latest_step) do
|
15
|
-
shell_command(@config[:build])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
data/lib/leg/commands/clean.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
class Leg::Commands::Clean < Leg::Commands::BaseCommand
|
2
|
-
def self.name
|
3
|
-
"clean"
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.summary
|
7
|
-
"Delete files generated by the build command"
|
8
|
-
end
|
9
|
-
|
10
|
-
def run
|
11
|
-
needs! :config
|
12
|
-
needs! :config_clean
|
13
|
-
|
14
|
-
select_step(current_or_latest_step) do
|
15
|
-
shell_command(@config[:clean])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
data/lib/leg/commands/diff.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
class Leg::Commands::Diff < Leg::Commands::BaseCommand
|
2
|
-
def self.name
|
3
|
-
"diff"
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.summary
|
7
|
-
"Display a diff between two versions of a file"
|
8
|
-
end
|
9
|
-
|
10
|
-
def run
|
11
|
-
needs! :config
|
12
|
-
|
13
|
-
step = @args.first || latest_step
|
14
|
-
step_idx = steps.index(step)
|
15
|
-
prev_step = steps[step_idx - 1]
|
16
|
-
|
17
|
-
FileUtils.cd(@config[:path]) do
|
18
|
-
shell_command("git diff --no-index #{prev_step} #{step}", exec: true)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
data/lib/leg/commands/edit.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
class Leg::Commands::Edit < Leg::Commands::BaseCommand
|
2
|
-
def self.name
|
3
|
-
"edit"
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.summary
|
7
|
-
"Open a file in a text editor"
|
8
|
-
end
|
9
|
-
|
10
|
-
def run
|
11
|
-
needs! :config
|
12
|
-
needs! :config_editor
|
13
|
-
|
14
|
-
step = current_or_latest_step
|
15
|
-
|
16
|
-
files = Dir[File.join(step_path(step), "**/*")].reject { |f| File.directory? f }
|
17
|
-
if files.length == 0
|
18
|
-
puts "Error: No files to edit."
|
19
|
-
exit!
|
20
|
-
elsif files.length == 1
|
21
|
-
file_path = files[0]
|
22
|
-
elsif @config[:default_file]
|
23
|
-
file_path = @config[:default_file]
|
24
|
-
else
|
25
|
-
puts "Error: You'll need to choose a file to edit."
|
26
|
-
exit!
|
27
|
-
end
|
28
|
-
|
29
|
-
select_step(step) do
|
30
|
-
shell_command("#{@config[:editor]}", file_path, exec: true)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
data/lib/leg/commands/expand.rb
DELETED
data/lib/leg/commands/ls.rb
DELETED
data/lib/leg/commands/next.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
class Leg::Commands::Next < Leg::Commands::BaseCommand
|
2
|
-
def self.name
|
3
|
-
"next"
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.summary
|
7
|
-
"Create a new step that is a copy of the latest step"
|
8
|
-
end
|
9
|
-
|
10
|
-
def run
|
11
|
-
needs! :config
|
12
|
-
|
13
|
-
latest_step = steps.last
|
14
|
-
next_step = (latest_step.to_i + 1).to_s
|
15
|
-
|
16
|
-
FileUtils.cd(@config[:path]) do
|
17
|
-
shell_command("cp -r #{latest_step} #{next_step}")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
data/lib/leg/commands/run.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
class Leg::Commands::Run < Leg::Commands::BaseCommand
|
2
|
-
def self.name
|
3
|
-
"run"
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.summary
|
7
|
-
"Build and run a version (latest by default) of the project"
|
8
|
-
end
|
9
|
-
|
10
|
-
def run
|
11
|
-
needs! :config
|
12
|
-
needs! :config_run
|
13
|
-
|
14
|
-
select_step(current_or_latest_step) do
|
15
|
-
shell_command(@config[:run], exec: true)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|