snaptoken 0.22.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a81cb9783bd03718bb76147934e37db517b9e1f6
4
- data.tar.gz: 6ec69608e410ab0c0ec3aaf728140b8dccdf0d90
3
+ metadata.gz: '006850149613e2b91770ee1d314f523a0e0741e2'
4
+ data.tar.gz: 4499961406d699b379850ae58c59d0e3251945c5
5
5
  SHA512:
6
- metadata.gz: 7dc3fdf69e5dba4127d71dbb357da64bd7de0846b6f810075effab046d9d6ebb9fd6ade61989f774a7d81462a97f37f8ca6614f25a253d19af63966c61ae8b9d
7
- data.tar.gz: f7678326bb314641b8e2bb8bb0f830061f45702c0ddd1b84d8beb6440dee138d0b614757d8c3713e865c169dcb3dfec0ccec57bdebe570aa7d98fd7a163a4a7f
6
+ metadata.gz: 9d6870227063fb6e61802d4838729a9797d56dba1baa17802384b3d3ea46ddb5a5886708ba7290e351db3f7b56314e74f121bb3a7271840490b8b61d904e018d
7
+ data.tar.gz: e7816626ea373b8c46f249a40acc499c19c76279499d9ebb65deab49778382a3e899a0b1feae248d700709eae5a697d2f5394b1b788e99163476d75fab5c4649
@@ -2,21 +2,48 @@ class Snaptoken::Commands::BaseCommand
2
2
  def initialize(args, config)
3
3
  @args = args
4
4
  @config = config
5
+ parseopts!
5
6
  end
6
7
 
7
8
  def self.name; raise NotImplementedError; end
8
9
  def self.summary; raise NotImplementedError; end
10
+ def setopts!(o); raise NotImplementedError; end
9
11
  def run; raise NotImplementedError; end
10
12
 
11
13
  def self.inherited(subclass)
12
14
  Snaptoken::Commands::LIST << subclass
13
15
  end
14
16
 
17
+ def parseopts!
18
+ parser = OptionParser.new do |o|
19
+ o.banner = "Usage: leg #{self.class.name} #{self.class.usage}"
20
+ self.class.summary.split("\n").each do |line|
21
+ o.separator " #{line}"
22
+ end
23
+ o.separator ""
24
+ o.separator "Options:"
25
+ setopts!(o)
26
+ o.on_tail("-h", "--help", "Show this message") do
27
+ puts o
28
+ exit
29
+ end
30
+ end
31
+ @opts = {}
32
+ parser.parse!(@args)
33
+ rescue OptionParser::InvalidOption => e
34
+ puts "#{e.message}"
35
+ puts
36
+ parser.parse("--help")
37
+ end
38
+
15
39
  ERROR_MSG = {
16
40
  config: {
17
41
  true: "You are not in a leg working directory.",
18
42
  false: "You are already in a leg working directory."
19
43
  },
44
+ config_sync: {
45
+ true: "The :sync option in leg.yml must be set to 'repo' or 'steps'."
46
+ },
20
47
  steps_folder: {
21
48
  true: "There is no steps folder.",
22
49
  false: "There is already a steps folder."
@@ -37,6 +64,9 @@ class Snaptoken::Commands::BaseCommand
37
64
  doc_out: {
38
65
  true: "There are no doc output files."
39
66
  },
67
+ cached_diffs: {
68
+ true: "There are no cached diffs."
69
+ },
40
70
  ftp: {
41
71
  true: "There is no ftp.yml file."
42
72
  }
@@ -54,6 +84,8 @@ class Snaptoken::Commands::BaseCommand
54
84
  case what
55
85
  when :config
56
86
  valid = true if @config
87
+ when :config_sync
88
+ valid = true if %w(repo steps).include?(@config[:sync])
57
89
  when :steps_folder
58
90
  valid = true if File.exist?(File.join(@config[:path], "steps"))
59
91
  when :steps
@@ -66,6 +98,8 @@ class Snaptoken::Commands::BaseCommand
66
98
  valid = true if File.exist?(File.join(@config[:path], "doc"))
67
99
  when :doc_out
68
100
  valid = true if File.exist?(File.join(@config[:path], "doc/html_out"))
101
+ when :cached_diffs
102
+ valid = true if File.exist?(File.join(@config[:path], ".cached-diffs"))
69
103
  when :ftp
70
104
  valid = true if File.exist?(File.join(@config[:path], "ftp.yml"))
71
105
  else
@@ -4,7 +4,15 @@ class Snaptoken::Commands::Deploy < Snaptoken::Commands::BaseCommand
4
4
  end
5
5
 
6
6
  def self.summary
7
- "Pushes output files in doc/ to production server"
7
+ "Push output files in doc/html_out/ to\n" +
8
+ "production server (requires ftp.yml)."
9
+ end
10
+
11
+ def self.usage
12
+ "[pattern...]"
13
+ end
14
+
15
+ def setopts!(o)
8
16
  end
9
17
 
10
18
  def run
@@ -4,7 +4,17 @@ class Snaptoken::Commands::Diff < Snaptoken::Commands::BaseCommand
4
4
  end
5
5
 
6
6
  def self.summary
7
- "Convert repo into a single file containing diffs for each step"
7
+ "Convert repo/ to steps.diff."
8
+ end
9
+
10
+ def self.usage
11
+ "[-q]"
12
+ end
13
+
14
+ def setopts!(o)
15
+ o.on("-q", "--quiet", "Don't output progress") do |q|
16
+ @opts[:quiet] = q
17
+ end
8
18
  end
9
19
 
10
20
  def run
@@ -21,12 +31,14 @@ class Snaptoken::Commands::Diff < Snaptoken::Commands::BaseCommand
21
31
  break if $1.strip == "-"
22
32
  f << "\n" unless step_num == 1
23
33
  step = Snaptoken::Step.from_commit_msg(step_num, $1.strip)
34
+ print "\r\e[K[repo/ -> steps.diff] #{step.folder_name}" unless @opts[:quiet]
24
35
  f << "~~~ step: #{step.commit_msg}\n"
25
36
  step_num += 1
26
37
  elsif line.chomp.length > 0
27
38
  f << line
28
39
  end
29
40
  end
41
+ print "\n" unless @opts[:quiet]
30
42
  end
31
43
  end
32
44
  end
@@ -6,11 +6,37 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
6
6
  end
7
7
 
8
8
  def self.summary
9
- "Renders files in doc folder into an HTML book"
9
+ "Render files in doc/ into an HTML book.\n" +
10
+ "(Automatically runs the `sync` command.)"
11
+ end
12
+
13
+ def self.usage
14
+ "[-c] [-z] [-q]"
15
+ end
16
+
17
+ def setopts!(o)
18
+ o.on("-c", "--cached", "Use cached diff HTML (much faster)") do |c|
19
+ @opts[:cached] = c
20
+ end
21
+
22
+ o.on("-z", "--zip", "Also create a .zip archive in doc/") do |z|
23
+ @opts[:zip] = z
24
+ end
25
+
26
+ o.on("-q", "--quiet", "Don't output progress") do |q|
27
+ @opts[:quiet] = q
28
+ end
10
29
  end
11
30
 
12
31
  def run
13
- needs! :config, :steps_folder, :steps, :doc
32
+ needs! :config, :doc
33
+ if @opts[:cached]
34
+ needs! :cached_diffs
35
+ else
36
+ sync_args = @opts[:quiet] ? ["--quiet"] : []
37
+ Snaptoken::Commands::Sync.new(sync_args, @config).run
38
+ @steps = nil # XXX just in case @steps were already cached
39
+ end
14
40
 
15
41
  FileUtils.cd(File.join(@config[:path], "doc")) do
16
42
  FileUtils.rm_rf("html_out")
@@ -21,7 +47,7 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
21
47
  copy_static_files
22
48
  write_css
23
49
  write_html_files(prerender_diffs)
24
- create_archive if @args.include? "-z"
50
+ create_archive if @opts[:zip]
25
51
  end
26
52
  end
27
53
 
@@ -66,7 +92,7 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
66
92
  end
67
93
 
68
94
  def prerender_diffs
69
- if @args.include? "-c"
95
+ if @opts[:cached]
70
96
  return Marshal.load(File.read("../.cached-diffs"))
71
97
  end
72
98
 
@@ -75,7 +101,7 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
75
101
  FileUtils.mkdir_p("0")
76
102
  last_step = Snaptoken::Step.new(0, nil, [])
77
103
  steps.each do |step|
78
- print "\r\e[K#{step.folder_name}"
104
+ print "\r\e[K[steps/ -> .cached-diffs] #{step.folder_name}" unless @opts[:quiet]
79
105
 
80
106
  diff = Snaptoken::Diff.new(@config, last_step, step)
81
107
 
@@ -83,7 +109,7 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
83
109
 
84
110
  last_step = step
85
111
  end
86
- puts
112
+ print "\n" unless @opts[:quiet]
87
113
  FileUtils.rmdir("0")
88
114
  end
89
115
  File.write("../.cached-diffs", Marshal.dump(diffs))
@@ -99,6 +125,7 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
99
125
  pages = Dir["*.md"].sort.map { |f| f.sub(/\.md$/, '') }
100
126
  pages.delete "00.index"
101
127
  pages.each.with_index do |page, idx|
128
+ print "\r\e[K[doc/ -> doc/html_out/] #{page}.html" unless @opts[:quiet]
102
129
  md = File.read("#{page}.md")
103
130
  md =~ /^# (.+)$/
104
131
  title = $1
@@ -131,6 +158,7 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
131
158
  File.write(File.join("html_out", "#{page}.html"), html)
132
159
  File.write(File.join("html_offline", "#{page}.html"), html)
133
160
  end
161
+ print "\n" unless @opts[:quiet]
134
162
 
135
163
  content = markdown.render(File.read("00.index.md"))
136
164
  content = Redcarpet::Render::SmartyPants.render(content)
@@ -4,7 +4,15 @@ class Snaptoken::Commands::Fancy < Snaptoken::Commands::BaseCommand
4
4
  end
5
5
 
6
6
  def self.summary
7
- "Run steps.diff through colordiff, diff-so-fancy, and less"
7
+ "Run steps.diff through colordiff,\n" +
8
+ "diff-so-fancy, and less."
9
+ end
10
+
11
+ def self.usage
12
+ ""
13
+ end
14
+
15
+ def setopts!(o)
8
16
  end
9
17
 
10
18
  def run
@@ -4,16 +4,34 @@ class Snaptoken::Commands::Help < Snaptoken::Commands::BaseCommand
4
4
  end
5
5
 
6
6
  def self.summary
7
- "Print out this help"
7
+ "Print out list of commands, or get help\n" +
8
+ "on a specific command."
9
+ end
10
+
11
+ def self.usage
12
+ "[<command>]"
13
+ end
14
+
15
+ def setopts!(o)
8
16
  end
9
17
 
10
18
  def run
11
- puts "Usage: leg <command> [args...]"
12
- puts
13
- puts "Commands:"
14
- Snaptoken::Commands::LIST.each do |cmd|
15
- puts " #{cmd.name}"
16
- puts " #{cmd.summary}"
19
+ if @args.empty?
20
+ puts "Usage: leg <command> [args...]"
21
+ puts
22
+ puts "Commands:"
23
+ Snaptoken::Commands::LIST.each do |cmd|
24
+ puts " #{cmd.name} #{cmd.usage}"
25
+ cmd.summary.split("\n").each do |line|
26
+ puts " #{line}"
27
+ end
28
+ end
29
+ puts
30
+ puts "For more help on a specific command, run `leg help <command>`."
31
+ elsif cmd = Snaptoken::Commands::LIST.find { |cmd| cmd.name == @args.first }
32
+ cmd.new(["--help"], @config)
33
+ else
34
+ puts "There is no '#{@args.first}' command."
17
35
  end
18
36
  end
19
37
  end
@@ -4,7 +4,17 @@ class Snaptoken::Commands::Ref < Snaptoken::Commands::BaseCommand
4
4
  end
5
5
 
6
6
  def self.summary
7
- "Convert a step number or name to a git commit reference"
7
+ "Get the commit hash in repo/ for a step\n" +
8
+ "name or step number. `leg <step-number>`\n" +
9
+ "can be used as a shortcut for\n" +
10
+ "`leg ref <step-number>`."
11
+ end
12
+
13
+ def self.usage
14
+ "[<step-name> | <step-number>]"
15
+ end
16
+
17
+ def setopts!(o)
8
18
  end
9
19
 
10
20
  def run
@@ -4,24 +4,47 @@ class Snaptoken::Commands::Repo < Snaptoken::Commands::BaseCommand
4
4
  end
5
5
 
6
6
  def self.summary
7
- "Convert steps folder into a version controlled repository"
7
+ "Convert steps/ to repo/. Doesn't overwrite\n" +
8
+ "repo/ unless forced."
9
+ end
10
+
11
+ def self.usage
12
+ "[-f] [-q]"
13
+ end
14
+
15
+ def setopts!(o)
16
+ o.on("-f", "--force", "Overwrite repo/ folder") do |f|
17
+ @opts[:force] = f
18
+ end
19
+
20
+ o.on("-q", "--quiet", "Don't output progress") do |q|
21
+ @opts[:quiet] = q
22
+ end
8
23
  end
9
24
 
10
25
  def run
11
- needs! :config, :steps_folder, :steps, not: :repo
26
+ needs! :config, :steps_folder, :steps
12
27
 
13
28
  FileUtils.cd(@config[:path])
14
29
 
30
+ if @opts[:force]
31
+ FileUtils.rm_rf("repo")
32
+ else
33
+ needs! not: :repo
34
+ end
35
+
15
36
  FileUtils.mkdir("repo")
16
37
  repo = Rugged::Repository.init_at("repo")
17
38
 
18
39
  steps.each do |step|
40
+ print "\r\e[K[steps/ -> repo/] #{step.folder_name}" unless @opts[:quiet]
19
41
  commit_oid = add_commit(repo, step, step_path(step))
20
42
 
21
43
  if step.name
22
44
  repo.references.create("refs/tags/#{step.name}", commit_oid)
23
45
  end
24
46
  end
47
+ print "\n" unless @opts[:quiet]
25
48
 
26
49
  if Dir.exist? "repo-extra"
27
50
  add_commit(repo, nil, [step_path(latest_step), "repo-extra"])
@@ -0,0 +1,75 @@
1
+ class Snaptoken::Commands::Sync < Snaptoken::Commands::BaseCommand
2
+ def self.name
3
+ "sync"
4
+ end
5
+
6
+ def self.summary
7
+ "Sync repo/, steps/, and steps.diff using\n" +
8
+ "one of them as the source. The <source> can\n" +
9
+ "be 'repo', 'steps', or 'diff'. The :sync\n" +
10
+ "option in leg.yml sets the default source.\n" +
11
+ "If only one possible source exists, then that\n" +
12
+ "is the default source."
13
+ end
14
+
15
+ def self.usage
16
+ "[-q] [<source>]"
17
+ end
18
+
19
+ def setopts!(o)
20
+ o.on("-q", "--quiet", "Don't output progress") do |q|
21
+ @opts[:quiet] = q
22
+ end
23
+ end
24
+
25
+ def run
26
+ needs! :config
27
+
28
+ source = nil
29
+ if !@args.empty?
30
+ source = @args.first
31
+ else
32
+ FileUtils.cd(@config[:path])
33
+ repo_exists = File.exist?("repo")
34
+ steps_exists = File.exist?("steps")
35
+ diff_exists = File.exist?("steps.diff")
36
+
37
+ if !repo_exists && !steps_exists && !diff_exists
38
+ puts "Error: nothing to sync from."
39
+ exit
40
+ end
41
+
42
+ if repo_exists && !steps_exists && !diff_exists
43
+ source = "repo"
44
+ elsif steps_exists && !repo_exists && !diff_exists
45
+ source = "steps"
46
+ elsif diff_exists && !repo_exists && !steps_exists
47
+ source = "diff"
48
+ else
49
+ needs! :config_sync
50
+ source = @config[:sync]
51
+ end
52
+ end
53
+
54
+ if ! %w(repo steps diff).include?(source)
55
+ puts "Error: sync source must be 'repo', 'steps', or 'diff'."
56
+ exit
57
+ end
58
+
59
+ needs! source.to_sym
60
+
61
+ args = @opts[:quiet] ? ["--quiet"] : []
62
+ case source.to_sym
63
+ when :repo
64
+ Snaptoken::Commands::Diff.new(args + [], @config).run
65
+ Snaptoken::Commands::Undiff.new(args + ["--force"], @config).run
66
+ when :steps
67
+ Snaptoken::Commands::Repo.new(args + ["--force"], @config).run
68
+ Snaptoken::Commands::Diff.new(args + [], @config).run
69
+ when :diff
70
+ Snaptoken::Commands::Undiff.new(args + ["--force"], @config).run
71
+ Snaptoken::Commands::Repo.new(args + ["--force"], @config).run
72
+ end
73
+ end
74
+ end
75
+
@@ -4,13 +4,34 @@ class Snaptoken::Commands::Undiff < Snaptoken::Commands::BaseCommand
4
4
  end
5
5
 
6
6
  def self.summary
7
- "Convert steps.diff to steps folder"
7
+ "Convert steps.diff to steps/. Doesn't\n" +
8
+ "overwrite steps/ unless forced."
9
+ end
10
+
11
+ def self.usage
12
+ "[-f] [-q]"
13
+ end
14
+
15
+ def setopts!(o)
16
+ o.on("-f", "--force", "Overwrite steps/ folder") do |f|
17
+ @opts[:force] = f
18
+ end
19
+
20
+ o.on("-q", "--quiet", "Don't output progress") do |q|
21
+ @opts[:quiet] = q
22
+ end
8
23
  end
9
24
 
10
25
  def run
11
- needs! :config, :diff, not: :steps_folder
26
+ needs! :config, :diff
12
27
 
13
28
  FileUtils.cd(@config[:path]) do
29
+ if @opts[:force]
30
+ FileUtils.rm_rf("steps")
31
+ else
32
+ needs! not: :steps_folder
33
+ end
34
+
14
35
  FileUtils.mkdir("steps")
15
36
  FileUtils.cd("steps") do
16
37
  File.open("../steps.diff", "r") do |f|
@@ -28,6 +49,8 @@ class Snaptoken::Commands::Undiff < Snaptoken::Commands::BaseCommand
28
49
  prev_step = step
29
50
  step = Snaptoken::Step.from_commit_msg(prev_step.number + 1, $1)
30
51
 
52
+ print "\r\e[K[steps.diff -> steps/] #{step.folder_name}" unless @opts[:quiet]
53
+
31
54
  if step.number == 1
32
55
  FileUtils.mkdir(step.folder_name)
33
56
  else
@@ -41,6 +64,7 @@ class Snaptoken::Commands::Undiff < Snaptoken::Commands::BaseCommand
41
64
  end
42
65
  end
43
66
  apply_diff(step, cur_diff) if cur_diff
67
+ print "\n" unless @opts[:quiet]
44
68
  end
45
69
  end
46
70
  end
@@ -4,13 +4,34 @@ class Snaptoken::Commands::Unrepo < Snaptoken::Commands::BaseCommand
4
4
  end
5
5
 
6
6
  def self.summary
7
- "Convert repository into steps folder"
7
+ "Convert repo/ to steps/. Doesn't overwrite\n" +
8
+ "steps/ unless forced."
9
+ end
10
+
11
+ def self.usage
12
+ "[-f] [-q]"
13
+ end
14
+
15
+ def setopts!(o)
16
+ o.on("-f", "--force", "Overwrite steps/ folder") do |f|
17
+ @opts[:force] = f
18
+ end
19
+
20
+ o.on("-q", "--quiet", "Don't output progress") do |q|
21
+ @opts[:quiet] = q
22
+ end
8
23
  end
9
24
 
10
25
  def run
11
- needs! :config, :repo, not: :steps_folder
26
+ needs! :config, :repo
12
27
 
13
28
  FileUtils.cd(@config[:path]) do
29
+ if @opts[:force]
30
+ FileUtils.rm_rf("steps")
31
+ else
32
+ needs! not: :steps_folder
33
+ end
34
+
14
35
  FileUtils.mkdir("steps")
15
36
 
16
37
  repo = Rugged::Repository.new("repo")
@@ -22,10 +43,12 @@ class Snaptoken::Commands::Unrepo < Snaptoken::Commands::BaseCommand
22
43
  break if commit.message.lines.first.strip == "-"
23
44
 
24
45
  step = Snaptoken::Step.from_commit_msg(idx + 1, commit.message.lines.first.strip)
46
+ print "\r\e[K[repo/ -> steps/] #{step.folder_name}" unless @opts[:quiet]
25
47
 
26
48
  repo.checkout(commit.oid, strategy: :force,
27
49
  target_directory: step_path(step))
28
50
  end
51
+ print "\n" unless @opts[:quiet]
29
52
  end
30
53
  end
31
54
  end
@@ -4,14 +4,14 @@ end
4
4
 
5
5
  require 'snaptoken/commands/base_command'
6
6
 
7
- require 'snaptoken/commands/deploy'
8
- require 'snaptoken/commands/diff'
9
7
  require 'snaptoken/commands/doc'
10
- require 'snaptoken/commands/help'
11
- require 'snaptoken/commands/pieces'
8
+ require 'snaptoken/commands/sync'
12
9
  require 'snaptoken/commands/fancy'
13
- require 'snaptoken/commands/ref'
10
+ require 'snaptoken/commands/diff'
14
11
  require 'snaptoken/commands/repo'
15
12
  require 'snaptoken/commands/undiff'
16
13
  require 'snaptoken/commands/unrepo'
14
+ require 'snaptoken/commands/ref'
15
+ require 'snaptoken/commands/deploy'
16
+ require 'snaptoken/commands/help'
17
17
 
@@ -1,5 +1,4 @@
1
1
  class Snaptoken::Diff
2
- # -r for recursive?
3
2
  GIT_DIFF_OPTIONS = "--histogram --unified=100000 --ignore-space-change --no-index"
4
3
 
5
4
  attr_reader :files, :html
data/lib/snaptoken.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'net/ftp'
3
+ require 'optparse'
3
4
  require 'yaml'
4
5
  require 'rugged'
5
6
  require 'redcarpet'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snaptoken
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.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-04-26 00:00:00.000000000 Z
11
+ date: 2017-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -69,9 +69,9 @@ files:
69
69
  - lib/snaptoken/commands/doc.rb
70
70
  - lib/snaptoken/commands/fancy.rb
71
71
  - lib/snaptoken/commands/help.rb
72
- - lib/snaptoken/commands/pieces.rb
73
72
  - lib/snaptoken/commands/ref.rb
74
73
  - lib/snaptoken/commands/repo.rb
74
+ - lib/snaptoken/commands/sync.rb
75
75
  - lib/snaptoken/commands/undiff.rb
76
76
  - lib/snaptoken/commands/unrepo.rb
77
77
  - lib/snaptoken/diff.rb
@@ -1,14 +0,0 @@
1
- class Snaptoken::Commands::Pieces < Snaptoken::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
-