Class: Gitoc::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/gitoc/cli.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



12
13
14
15
16
17
18
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/gitoc/cli.rb', line 12

def check
  init_base

  # Get all repositories from the filesystem
  # and tag them with :fs
  repositories = repositories_fs.map do |repository_fs|
    [repository_fs, [:fs]]
  end

  # Add missing repositories from the GiTOC file
  # and tag all repositories from the GiTOC file with :toc
  repositories_gitoc.each do |repository_gitoc|
    _, tags = repositories.find {|repository_fs, _| repository_fs == repository_gitoc }
    if tags
      tags << :toc
    else
      repositories << [repository_gitoc, [:toc]]
    end
  end

  # Sort repositories list
  # and build table rows: [path, url, comment]
  rows = repositories.sort_by {|repository, _| repository.rel_path }.map do |repository, tags|
    path, url = repository.to_hash.values
    url = "-" if url.nil? || url.empty?
    comment = tags.include?(:fs) && tags.include?(:toc) ? "" : {fs: "not in GiTOC", toc: "not on filesystem"}[tags.first]

    [path, url, comment]
  end

  print_table rows  
end

#cloneObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gitoc/cli.rb', line 57

def clone
  init_base

  each_repository do |repo|
    if repo.exist?
      puts "Skip repository, #{repo.path} already exists."
      next
    end

    repo.clone
  end
end

#clone_or_pullObject



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/gitoc/cli.rb', line 85

def clone_or_pull
  init_base

  each_repository do |repo|
    if repo.exist?
      repo.pull
    else
      repo.clone
    end
  end
end

#generateObject



46
47
48
49
50
51
52
53
54
# File 'lib/gitoc/cli.rb', line 46

def generate
  init_base

  toc = repositories_fs.map(&:to_hash)

  # Write git_toc file
  gitoc.write toc.to_yaml
  puts "Write #{gitoc}"
end

#pullObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gitoc/cli.rb', line 71

def pull
  init_base

  each_repository do |repo|
    unless repo.exist?
      puts "Skip repository, #{repo.path} doesn't exist."
      next
    end

    repo.pull
  end
end