Class: Snaptoken::Commands::Repo

Inherits:
BaseCommand show all
Defined in:
lib/snaptoken/commands/repo.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::ERROR_MSG

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

inherited, #initialize, #latest_step, #needs!, #parseopts!, #step_path, #steps

Constructor Details

This class inherits a constructor from Snaptoken::Commands::BaseCommand

Class Method Details

.nameObject



2
3
4
# File 'lib/snaptoken/commands/repo.rb', line 2

def self.name
  "repo"
end

.summaryObject



6
7
8
9
# File 'lib/snaptoken/commands/repo.rb', line 6

def self.summary
  "Convert steps/ to repo/. Doesn't overwrite\n" +
  "repo/ unless forced."
end

.usageObject



11
12
13
# File 'lib/snaptoken/commands/repo.rb', line 11

def self.usage
  "[-f] [-q]"
end

Instance Method Details

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/snaptoken/commands/repo.rb', line 25

def run
  needs! :config, :steps_folder, :steps

  FileUtils.cd(@config[:path])

  if @opts[:force]
    FileUtils.rm_rf("repo")
  else
    needs! not: :repo
  end

  FileUtils.mkdir("repo")
  repo = Rugged::Repository.init_at("repo")

  steps.each do |step|
    print "\r\e[K[steps/ -> repo/] #{step.folder_name}" unless @opts[:quiet]
    commit_oid = add_commit(repo, step, step_path(step))

    if step.name
      repo.references.create("refs/tags/#{step.name}", commit_oid)
    end
  end
  print "\n" unless @opts[:quiet]

  if Dir.exist? "repo-extra"
    add_commit(repo, nil, [step_path(latest_step), "repo-extra"])
  end

  repo.checkout_head(strategy: :force)
end

#setopts!(o) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/snaptoken/commands/repo.rb', line 15

def setopts!(o)
  o.on("-f", "--force", "Overwrite repo/ folder") do |f|
    @opts[:force] = f
  end

  o.on("-q", "--quiet", "Don't output progress") do |q|
    @opts[:quiet] = q
  end
end