Class: Alf::Shell::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/alf/shell/command/main.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db = Alf.connect(Path.pwd)) ⇒ Main

Creates a command instance



58
59
60
61
# File 'lib/alf/shell/command/main.rb', line 58

def initialize(db = Alf.connect(Path.pwd))
  @database = db
  @rendering_options = {}
end

Instance Attribute Details

#databaseObject

Connection instance to use to get base relations



46
47
48
# File 'lib/alf/shell/command/main.rb', line 46

def database
  @database
end

#renderer_classObject

Output renderer



52
53
54
# File 'lib/alf/shell/command/main.rb', line 52

def renderer_class
  @renderer_class
end

#rendering_optionsObject (readonly)

Rendering options



55
56
57
# File 'lib/alf/shell/command/main.rb', line 55

def rendering_options
  @rendering_options
end

#stdin_operandObject

Alf’s options



49
50
51
# File 'lib/alf/shell/command/main.rb', line 49

def stdin_operand
  @stdin_operand
end

Class Method Details

.experimental_operators(sort_by_name = true) ⇒ Object



14
15
16
17
18
19
# File 'lib/alf/shell/command/main.rb', line 14

def experimental_operators(sort_by_name = true)
  ops = subcommands.select{|cmd|
    cmd.operator? and cmd.relational? and cmd.experimental?
  }
  sort_operators(ops, sort_by_name)
end

.non_relational_operators(sort_by_name = true) ⇒ Object



21
22
23
24
25
26
# File 'lib/alf/shell/command/main.rb', line 21

def non_relational_operators(sort_by_name = true)
  ops = subcommands.select{|cmd|
    cmd.operator? and !cmd.relational?
  }
  sort_operators(ops, sort_by_name)
end

.other_non_relational_commands(sort_by_name = true) ⇒ Object



28
29
30
31
32
33
# File 'lib/alf/shell/command/main.rb', line 28

def other_non_relational_commands(sort_by_name = true)
  ops = subcommands.select{|cmd|
    cmd.command?
  }
  sort_operators(ops, sort_by_name)
end

.relational_operators(sort_by_name = true) ⇒ Object



7
8
9
10
11
12
# File 'lib/alf/shell/command/main.rb', line 7

def relational_operators(sort_by_name = true)
  ops = subcommands.select{|cmd|
     cmd.operator? and cmd.relational? and !cmd.experimental?
  }
  sort_operators(ops, sort_by_name)
end

Instance Method Details

#execute(argv) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/alf/shell/command/main.rb', line 123

def execute(argv)
  # special case where a .alf file is provided
  if argv.empty? or (argv.size == 1 && Path(argv.first).exist?)
    argv.unshift("exec")
  end

  # compile the operator, render and returns it
  compile(argv){ super }.tap do |op|
    render(op.to_cog) if op && requester
  end
end

#pretty=(val) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/alf/shell/command/main.rb', line 135

def pretty=(val)
  @rendering_options[:pretty] = val
  if val && (hl = highline)
    @rendering_options[:trim_at] = hl.output_cols
    @rendering_options[:page_at] = hl.output_rows
  end
  val
end