Class: Pod::Command::GiteeRepo::Add

Inherits:
Pod::Command::GiteeRepo show all
Defined in:
lib/pod/command/gitee_repo/add.rb

Constant Summary collapse

UTIL =
Pod::GiteeRepo::GiteeRepoUtil

Instance Method Summary collapse

Methods inherited from Pod::Command::GiteeRepo

#init

Constructor Details

#initialize(argv) ⇒ Add

Returns a new instance of Add.



21
22
23
24
25
26
# File 'lib/pod/command/gitee_repo/add.rb', line 21

def initialize(argv)
  init
  @name, @url = argv.shift_argument, argv.shift_argument
  @silent = argv.flag?('silent', false)
  super
end

Instance Method Details

#create_artpodrc_file(repo_dir_root) ⇒ Object

Creates the .artpodrc file which contains the repository’s url in the root of the Spec repo

Parameters:

  • repo_dir_root (String)

    root of the Spec repo



86
87
88
89
90
91
92
# File 'lib/pod/command/gitee_repo/add.rb', line 86

def create_artpodrc_file(repo_dir_root)
  artpodrc_path = "#{repo_dir_root}/.artpodrc"
  artpodrc = File.new(artpodrc_path, "wb")
  artpodrc << @url
  artpodrc.close
  artpodrc_path
end

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/pod/command/gitee_repo/add.rb', line 35

def run
  UI.section("Retrieving index from `#{@url}` into local spec repo `#{@name}`") do
    # Check if a repo with the same name under repos/ already exists
    repos_path = "#{Pod::Config.instance.home_dir}/repos"

    raise Informative, "Path #{repos_path}/#{@name} already exists - remove it first, "\
    "or run 'pod gitee-repo update #{@name}' to update it" if File.exist?("#{repos_path}/#{@name}") && !@silent

    # Check if a repo with the same name under gitee-repos/ already exists
    repo_dir_root = "#{@gitee_repos_dir}/#{@name}"

    raise Informative, "Path #{repo_dir_root} already exists - remove it first, "\
    "or run 'pod gitee-repo update #{@name}' to update it" if File.exist?(repo_dir_root) && !@silent

    FileUtils::mkdir_p repo_dir_root

    repo_dir_specs = "#{repo_dir_root}/Specs"
    begin
      downloader = Pod::Downloader::Http.new(repo_dir_specs, "#{@url}/index/fetchIndex", :type => 'tgz', :indexDownload => true)
      downloader.download
    rescue => e
      FileUtils.remove_entry_secure(repo_dir_root, :force => true)
      raise Informative, "Error getting the index from Gitee Repo at: '#{@url}' : #{e.message}"
    end

    begin
    UTIL.cleanup_index_download(repo_dir_specs)
    UTIL.del_redundant_spec_dir("#{repo_dir_specs}/Specs")
    rescue => e
      UI.warn("Failed cleaning up temp files in #{repo_dir_specs}")
    end

    begin
      artpodrc_path = create_artpodrc_file(repo_dir_root)
    rescue => e
      raise Informative, "Cannot create file '#{artpodrc_path}' because : #{e.message}."\
                          '- your Gitee-backed Specs repo will not work correctly without it!'
    end
    # Create a local git repository in the newly added Gitee local repo
    system "cd '#{repo_dir_root}' && git init && git add . && git commit -m 'Gitee repo init'"

    # Create local repo under repos/ which is a remote for the new local git repository
    system "cd '#{repos_path}' && git clone file://#{repo_dir_root}"
  end
  UI.puts "Successfully added repo #{@name}".green unless @silent
end

#validate!Object



28
29
30
31
32
33
# File 'lib/pod/command/gitee_repo/add.rb', line 28

def validate!
  super
  unless @name && @url
    help! 'This command requires both a repo name and a url.'
  end
end