Class: Aspera::Cli::Command

Inherits:
Struct
  • Object
show all
Defined in:
lib/aspera/cli/command.rb,
lib/aspera/cli/command.rb,
lib/aspera/cli/command/mount.rb,
lib/aspera/cli/command/registry.rb

Overview

Declares a single command node in the flat registry.

Defined Under Namespace

Classes: Mount, Registry

Constant Summary collapse

READ_ONLY_IDS =

Ids of the commands read-only by default (read_only: :default): they change nothing

%i[list show status info health ls browse find].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Command

Returns a new instance of Command.



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/aspera/cli/command.rb', line 45

def initialize(**kwargs)
  Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
  kwargs[:read_only] = :default if kwargs[:read_only].nil?
  Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
  # Coerce each element of arguments: from Hash to Argument if needed
  if kwargs[:arguments]
    kwargs[:arguments] = kwargs[:arguments].map do |a|
      a.is_a?(Hash) ? Argument.new(**a) : a
    end
  end
  kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
  super
end

Instance Attribute Details

#action ⇒ Object (readonly)

Instance method (Symbol) or inline block (Proc) called when this is a leaf command



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end

#aliases ⇒ Object (readonly)

Alternative names accepted for this command (each resolves to this command's id)



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end

#arguments ⇒ Object (readonly)

Positional arguments, in order. The first Argument with type: :identifier is treated as the instance identifier for intermediate nodes (consumed in Phase A) and leaf nodes.



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end

#description ⇒ Object (readonly)

User-facing help text



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end

#parent ⇒ Object (readonly)

Full path to parent; nil for root commands



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end

#query_schema ⇒ Object (readonly)

Schema path for --query help; when set, the runner hints --query=help



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end

#transfer_paths ⇒ Object (readonly)

File-list resolution delegated to TransferAgent; mutually exclusive with arguments



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end

Class Method Details

.action_method(path) ⇒ Symbol

Derive the implicit action method name from a path array. e.g. [:admin, :user, :list] -> :action_admin_user_list

Parameters:

  • path (Array<Symbol>)

Returns:

  • (Symbol)


64
65
66
# File 'lib/aspera/cli/command.rb', line 64

def action_method(path)
  :"action_#{path.join('_')}"
end

Instance Method Details

#action_method_name ⇒ Symbol

Derive the implicit action method name from the full path.

Returns:

  • (Symbol)


82
83
84
# File 'lib/aspera/cli/command.rb', line 82

def action_method_name
  self.class.action_method(full_path)
end

#condition=(value) ⇒ Object

Instance method returning Boolean; if false command is hidden from dispatch



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end

#full_path ⇒ Array<Symbol>

Compute the full path as Array from parent + id.

Returns:

  • (Array<Symbol>)


76
77
78
# File 'lib/aspera/cli/command.rb', line 76

def full_path
  Array(parent) + [id]
end

#id=(value) ⇒ Object

Unique identifier within its parent's namespace



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end

#mount=(value) ⇒ Object

Expose children of another plugin's registry under this node



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end

#read_only=(value) ⇒ Object

Leaf only: the command changes nothing (on the server or locally), so it can be repeated (option poll). :default (default): read-only if the id is one of READ_ONLY_IDS (list, show, ...)



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end

#read_only? ⇒ Boolean

Returns true if the command changes nothing: explicit read_only, or from its id (READ_ONLY_IDS).

Returns:

  • (Boolean) —

    true if the command changes nothing: explicit read_only, or from its id (READ_ONLY_IDS)



70
71
72
# File 'lib/aspera/cli/command.rb', line 70

def read_only?
  read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
end

#security=(value) ⇒ Object

Most restrictive security level at which the command is available (:low: executes code), see Security



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end

#setup=(value) ⇒ Object

Instance method called before dispatching to children; returns Hash merged into ctx



29
30
31
32
33
34
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
81
82
83
84
85
# File 'lib/aspera/cli/command.rb', line 29

Command = Struct.new(
  :id,
  :parent,
  :description,
  :arguments,
  :action,
  :setup,
  :aliases,
  :transfer_paths,
  :condition,
  :query_schema,
  :mount,
  :security,
  :read_only,
  keyword_init: true
) do
  def initialize(**kwargs)
    Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
    kwargs[:read_only] = :default if kwargs[:read_only].nil?
    Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
    # Coerce each element of arguments: from Hash to Argument if needed
    if kwargs[:arguments]
      kwargs[:arguments] = kwargs[:arguments].map do |a|
        a.is_a?(Hash) ? Argument.new(**a) : a
      end
    end
    kwargs[:mount] = Command::Mount.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
    super
  end

  class << self
    # Derive the implicit action method name from a path array.
    # e.g. [:admin, :user, :list] -> :action_admin_user_list
    # @param path [Array<Symbol>]
    # @return [Symbol]
    def action_method(path)
      :"action_#{path.join('_')}"
    end
  end

  # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
  def read_only?
    read_only.eql?(:default) ? Command::READ_ONLY_IDS.include?(id) : read_only
  end

  # Compute the full path as Array<Symbol> from parent + id.
  # @return [Array<Symbol>]
  def full_path
    Array(parent) + [id]
  end

  # Derive the implicit action method name from the full path.
  # @return [Symbol]
  def action_method_name
    self.class.action_method(full_path)
  end
end