Class: OsCtl::Cli::Repository

Inherits:
Command
  • Object
show all
Includes:
Assets, Attributes
Defined in:
lib/osctl/cli/repository.rb

Constant Summary collapse

FIELDS =
%i(pool name url enabled)
IMAGE_FIELDS =
%i(vendor variant arch distribution version tags cached)
IMAGE_FILTERS =
%i(vendor variant arch distribution version tag cached)

Instance Attribute Summary

Attributes inherited from Command

#args, #gopts, #opts

Instance Method Summary collapse

Methods included from Attributes

#do_set_attr, #do_unset_attr

Methods included from Assets

#print_assets

Methods inherited from Command

#cli_opt, #format_output, #initialize, #osctld_call, #osctld_fmt, #osctld_open, #osctld_resp, #require_args!, run

Methods included from Utils::Humanize

#break_interval, #format_long_duration, #format_percent, #format_short_duration, #humanize_data, #humanize_time_ns, #parse_data

Constructor Details

This class inherits a constructor from OsCtl::Cli::Command

Instance Method Details

#addObject



46
47
48
49
# File 'lib/osctl/cli/repository.rb', line 46

def add
  require_args!('name', 'url')
  osctld_fmt(:repo_add, pool: gopts[:pool], name: args[0], url: args[1])
end

#assetsObject



90
91
92
93
# File 'lib/osctl/cli/repository.rb', line 90

def assets
  require_args!('name')
  print_assets(:repo_assets, name: args[0], pool: gopts[:pool])
end

#deleteObject



51
52
53
54
# File 'lib/osctl/cli/repository.rb', line 51

def delete
  require_args!('name')
  osctld_fmt(:repo_delete, pool: gopts[:pool], name: args[0])
end

#disableObject



61
62
63
64
# File 'lib/osctl/cli/repository.rb', line 61

def disable
  require_args!('name')
  osctld_fmt(:repo_disable, pool: gopts[:pool], name: args[0])
end

#enableObject



56
57
58
59
# File 'lib/osctl/cli/repository.rb', line 56

def enable
  require_args!('name')
  osctld_fmt(:repo_enable, pool: gopts[:pool], name: args[0])
end

#image_listObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/osctl/cli/repository.rb', line 95

def image_list
  if opts[:list]
    puts IMAGE_FIELDS.join("\n")
    return
  end

  require_args!('name')

  cmd_opts = {pool: gopts[:pool], name: args[0]}

  IMAGE_FILTERS.each do |v|
    cmd_opts[v] = opts[v] if opts[v]
  end

  cmd_opts[:cached] = true if opts[:cached]
  cmd_opts[:cached] = false if opts[:uncached]

  fmt_opts = {
    layout: :columns,
    sort: opts[:sort] && opts[:sort].split(',').map(&:to_sym),
  }
  fmt_opts[:header] = false if opts['hide-header']
  cols = opts[:output] ? opts[:output].split(',').map(&:to_sym) : IMAGE_FIELDS

  if i = cols.index(:tags)
    cols[i] = {
      name: :tags,
      label: 'TAGS',
      align: 'left',
      display: Proc.new { |values| values.join(',') },
    }
  end

  osctld_fmt(:repo_image_list, cmd_opts, cols, fmt_opts)
end

#listObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/osctl/cli/repository.rb', line 12

def list
  if opts[:list]
    puts FIELDS.join("\n")
    return
  end

  cmd_opts = {pool: gopts[:pool]}
  fmt_opts = {layout: :columns}

  cmd_opts[:names] = args if args.count > 0

  fmt_opts[:header] = false if opts['hide-header']
  cols = opts[:output] ? opts[:output].split(',').map(&:to_sym) : FIELDS

  osctld_fmt(:repo_list, cmd_opts, cols, fmt_opts)
end

#set_attrObject



71
72
73
74
75
76
77
78
79
# File 'lib/osctl/cli/repository.rb', line 71

def set_attr
  require_args!('name', 'attribute', 'value')
  do_set_attr(
    :repo_set,
    {name: args[0], pool: gopts[:pool]},
    args[1],
    args[2],
  )
end

#set_urlObject



66
67
68
69
# File 'lib/osctl/cli/repository.rb', line 66

def set_url
  require_args!('name', 'url')
  osctld_fmt(:repo_set, name: args[0], pool: gopts[:pool], url: args[1])
end

#showObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/osctl/cli/repository.rb', line 29

def show
  if opts[:list]
    puts FIELDS.join("\n")
    return
  end

  require_args!('name')

  cmd_opts = {name: args[0], pool: gopts[:pool]}
  fmt_opts = {layout: :rows}

  fmt_opts[:header] = false if opts['hide-header']
  cols = opts[:output] ? opts[:output].split(',').map(&:to_sym) : FIELDS

  osctld_fmt(:repo_show, cmd_opts, cols, fmt_opts)
end

#unset_attrObject



81
82
83
84
85
86
87
88
# File 'lib/osctl/cli/repository.rb', line 81

def unset_attr
  require_args!('name', 'attribute')
  do_unset_attr(
    :repo_unset,
    {name: args[0], pool: gopts[:pool]},
    args[1],
  )
end