Class: GitlabCli::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/gitlab_cli/cli.rb

Instance Method Summary collapse

Instance Method Details

#projectsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gitlab_cli/cli.rb', line 24

def projects
  if options['pager'] && options['nopager']
    GitlabCli.ui.error "Cannot specify --nopager and --pager options together. Choose one."
    exit 1
  end

  projects = GitlabCli::Util::Projects.get_all
  formatted_projects = ""
  pager = ENV['pager'] || 'less'

  projects.each do |p|
    formatted_projects << "%s:\t%s\n" % [p.id, p.path_with_namespace]
  end
  
  if ((GitlabCli::Config[:display_results_in_pager] && !options['nopager']) || options['pager'])
    unless system("echo %s | %s" % [Shellwords.escape(formatted_projects), pager])
      GitlabCli.ui.error "Problem displaying projects in pager"
      exit 1
    end
  else 
    GitlabCli.ui.info formatted_projects
  end
end

#snippets(project) ⇒ Object



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/gitlab_cli/cli.rb', line 56

def snippets(project)
  if options['pager'] && options['nopager']
    GitlabCli.ui.error "Cannot specify --nopager and --pager options together. Choose one."
    exit 1
  end

  snippets = GitlabCli::Util::Snippets.get_all(project)
  formatted_snippets = ""
  pager = ENV['pager'] || 'less'

  snippets.each do |s|
    formatted_snippets << "%s:\t%s - %s\n" % [s.id, s.title, s.file_name]
  end
  GitlabCli.ui.info "This project does not have any snippets.\n" if snippets.size == 0

  if ((GitlabCli::Config[:display_results_in_pager] && !options['nopager']) || options['pager'])
    unless system("echo %s | %s" % [Shellwords.escape(formatted_snippets), pager])
      GitlabCli.ui.error "Problem displaying snippets in pager"
      exit 1
    end
  else 
    GitlabCli.ui.info formatted_snippets
  end

end

#versionObject



14
15
16
# File 'lib/gitlab_cli/cli.rb', line 14

def version
  GitlabCli.ui.info "Gitlab CLI version %s" % [GitlabCli::VERSION]
end