Class: Leg::Commands::Init

Inherits:
BaseCommand show all
Defined in:
lib/leg/commands/init.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#config, #opts

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

#git_to_litdiff!, inherited, #initialize, #litdiff_to_git!, #needs!, #output, #parseopts!

Constructor Details

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

Class Method Details

.nameObject



4
5
6
# File 'lib/leg/commands/init.rb', line 4

def self.name
  "init"
end

.summaryObject



8
9
10
# File 'lib/leg/commands/init.rb', line 8

def self.summary
  "Initialize a new leg project."
end

.usageObject



12
13
14
# File 'lib/leg/commands/init.rb', line 12

def self.usage
  "[new-dir]"
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/leg/commands/init.rb', line 19

def run
  if @config
    puts "You are already in a leg working directory."
    return false
  end

  if new_dir = @args.first
    if File.exist?(new_dir)
      puts "Error: directory already exists."
      return false
    end
    FileUtils.mkdir(new_dir)
    FileUtils.cd(new_dir)
  end

  FileUtils.mkdir_p(".leg/repo")
  FileUtils.mkdir_p("step")
  FileUtils.mkdir_p("doc")
  File.write("doc/tutorial.litdiff", "")
  File.write("leg.yml", "---\n")

  config = Leg::Config.new(FileUtils.pwd)
  git = Leg::Representations::Git.new(config)
  git.init!
end

#setopts!(o) ⇒ Object



16
17
# File 'lib/leg/commands/init.rb', line 16

def setopts!(o)
end