Class: D2::Commands::Clone

Inherits:
D2::Command
  • Object
show all
Defined in:
lib/d2/commands/clone.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Formatter

#logger

Class Method Details

.helpObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/d2/commands/clone.rb', line 21

def self.help
  <<~EOF
    Clone a repository.
    Supports any git url, as well as fragments.

    E.g. The following would all clone https://github.com/owner/Repo.git
     {{info:git@github.com:owner/Repo.git
     https://github.com/owner/Repo.git
     owner/Repo
     Repo}}

    {{italic:Default Provider, when none specified, is #{ D2::Config.get('git', 'default_provider')}
    Default Repo Owner, when none specified, is #{ D2::Config.get('git', 'default_owner')}}}

    Usage: {{command:#{D2::TOOL_NAME} clone <repo>}}
  EOF
end

Instance Method Details

#call(args, _name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/d2/commands/clone.rb', line 6

def call(args, _name)
  git_repo = D2::Helpers::Git::LocalRepo.new(args.shift)

  unless Dir.exist?(git_repo.path_on_disk)
    require 'fileutils'
    FileUtils.mkdir_p(File.dirname(git_repo.path_on_disk))

    url = git_repo.url(type: 'ssh')
    logger.info "Cloning #{url}"
    CLI::Kit::System.system("git clone #{url} #{git_repo.path_on_disk}")
  end

  D2::FILE_DESCRIPTOR.write("cd #{git_repo.path_on_disk}")
end