oleg 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b7f5e28e44643080bb4f06b3396701c0bdce1693
4
+ data.tar.gz: 0c1ab8f6502b31450ea97af8498d4a08bf54ec56
5
+ SHA512:
6
+ metadata.gz: d4a7c99b7d778a0fce3d5af4bd14a8e7a9cdf1af4ba3414f13d11382928673c1eda2587dab92988292aed8de347e4ed0117ae9672f6377ef6ec5a698247c7ed8
7
+ data.tar.gz: ae2f6ce2b82963ce815cf68461cf9edb12ba24044a4d827d8c8273609fbcbef5ca48084b3e04fe2b7c831c23d804a124c57e1724451f43ce8d259b1474eb6064
data/bin/leg ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../lib')
4
+
5
+ require 'leg'
6
+
7
+ cli = Leg::CLI.new
8
+ cli.run(ARGV)
9
+
data/lib/leg/cli.rb ADDED
@@ -0,0 +1,38 @@
1
+ class Leg::CLI
2
+ CONFIG_FILE = "leg.yml"
3
+
4
+ def initialize
5
+ initial_dir = FileUtils.pwd
6
+
7
+ last_dir = nil
8
+ while FileUtils.pwd != last_dir
9
+ if File.exist?(CONFIG_FILE)
10
+ @config = YAML.load(File.read(CONFIG_FILE))
11
+ unless @config.is_a? Hash
12
+ puts "Error: Invalid config file."
13
+ exit!
14
+ end
15
+ @config[:path] = FileUtils.pwd
16
+ @config[:step_path] = last_dir
17
+ @config[:orig_path] = initial_dir
18
+ break
19
+ end
20
+
21
+ last_dir = FileUtils.pwd
22
+ FileUtils.cd('..')
23
+ end
24
+
25
+ FileUtils.cd(initial_dir)
26
+ end
27
+
28
+ def run(args)
29
+ args = ["help"] if args.empty?
30
+ cmd_name = args.shift.downcase
31
+ if cmd = Leg::Commands::LIST.find { |cmd| cmd.name == cmd_name }
32
+ cmd.new(args, @config).run
33
+ else
34
+ puts "There is no '#{cmd_name}' command. Run `leg help` for help."
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,87 @@
1
+ class Leg::Commands::BaseCommand
2
+ def initialize(args, config)
3
+ @args = args
4
+ @config = config
5
+ end
6
+
7
+ def self.name; raise NotImplementedError; end
8
+ def self.summary; raise NotImplementedError; end
9
+ def run; raise NotImplementedError; end
10
+
11
+ def self.inherited(subclass)
12
+ Leg::Commands::LIST << subclass
13
+ end
14
+
15
+ ERROR_MSG = {
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
+ }
22
+
23
+ def needs!(what)
24
+ valid = false
25
+
26
+ case what
27
+ when :config
28
+ 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
+ else
38
+ raise NotImplementedError
39
+ end
40
+
41
+ if !valid
42
+ puts "Error: " + ERROR_MSG[what]
43
+ exit!
44
+ end
45
+ end
46
+
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
+ def steps
58
+ @steps ||= Dir[File.join(@config[:path], "*")].map do |f|
59
+ name = File.basename(f)
60
+ name if File.directory?(f) && name =~ /\A\d+(\.\d+)*\z/
61
+ end.compact.sort_by { |s| s.split(".").map(&:to_i) }
62
+ end
63
+
64
+ def current_step
65
+ if @config[:step_path]
66
+ File.basename(@config[:step_path])
67
+ end
68
+ end
69
+
70
+ def latest_step
71
+ steps.last
72
+ end
73
+
74
+ def current_or_latest_step
75
+ current_step || latest_step
76
+ end
77
+
78
+ def step_path(step)
79
+ File.join(@config[:path], step)
80
+ end
81
+
82
+ def select_step(step, &block)
83
+ puts "Selecting step: #{step}"
84
+ FileUtils.cd(step_path(step), &block)
85
+ end
86
+ end
87
+
@@ -0,0 +1,19 @@
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
+
@@ -0,0 +1,19 @@
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
+
@@ -0,0 +1,14 @@
1
+ class Leg::Commands::Contract < Leg::Commands::BaseCommand
2
+ def self.name
3
+ "contract"
4
+ end
5
+
6
+ def self.summary
7
+ "Package an expanded leg directory into a single .leg file"
8
+ end
9
+
10
+ def run
11
+ puts "Not implemented"
12
+ end
13
+ end
14
+
@@ -0,0 +1,22 @@
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
+
@@ -0,0 +1,34 @@
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
+
@@ -0,0 +1,14 @@
1
+ class Leg::Commands::Expand < Leg::Commands::BaseCommand
2
+ def self.name
3
+ "expand"
4
+ end
5
+
6
+ def self.summary
7
+ "Expand a .leg file into a working directory"
8
+ end
9
+
10
+ def run
11
+ puts "Not implemented"
12
+ end
13
+ end
14
+
@@ -0,0 +1,20 @@
1
+ class Leg::Commands::Help < Leg::Commands::BaseCommand
2
+ def self.name
3
+ "help"
4
+ end
5
+
6
+ def self.summary
7
+ "Print out this help"
8
+ end
9
+
10
+ def run
11
+ puts "Usage: leg <command> [args...]"
12
+ puts
13
+ puts "Commands:"
14
+ Leg::Commands::LIST.each do |cmd|
15
+ puts " #{cmd.name}"
16
+ puts " #{cmd.summary}"
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,16 @@
1
+ class Leg::Commands::Ls < Leg::Commands::BaseCommand
2
+ def self.name
3
+ "ls"
4
+ end
5
+
6
+ def self.summary
7
+ "List step directories in order"
8
+ end
9
+
10
+ def run
11
+ needs! :config
12
+
13
+ steps.each { |s| puts s }
14
+ end
15
+ end
16
+
@@ -0,0 +1,21 @@
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
+
@@ -0,0 +1,14 @@
1
+ class Leg::Commands::Pieces < Leg::Commands::BaseCommand
2
+ def self.name
3
+ "pieces"
4
+ end
5
+
6
+ def self.summary
7
+ "Print an inventory of the number of tokens used between two steps"
8
+ end
9
+
10
+ def run
11
+ puts "Not implemented"
12
+ end
13
+ end
14
+
@@ -0,0 +1,19 @@
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
+
@@ -0,0 +1,18 @@
1
+ module Leg::Commands
2
+ LIST = []
3
+ end
4
+
5
+ require 'leg/commands/base_command'
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
+ require 'leg/commands/help'
14
+ require 'leg/commands/ls'
15
+ require 'leg/commands/next'
16
+ require 'leg/commands/pieces'
17
+ require 'leg/commands/run'
18
+
data/lib/leg.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'fileutils'
2
+ require 'yaml'
3
+
4
+ module Leg
5
+ end
6
+
7
+ require 'leg/cli'
8
+ require 'leg/commands'
9
+
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oleg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Ruten
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: jeremy.ruten@gmail.com
15
+ executables:
16
+ - leg
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/leg
21
+ - lib/leg.rb
22
+ - lib/leg/cli.rb
23
+ - lib/leg/commands.rb
24
+ - 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
+ - lib/leg/commands/help.rb
32
+ - lib/leg/commands/ls.rb
33
+ - lib/leg/commands/next.rb
34
+ - lib/leg/commands/pieces.rb
35
+ - lib/leg/commands/run.rb
36
+ homepage: https://github.com/yjerem/leg
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.6.8
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: tools for .leg files
60
+ test_files: []