Method: Yast::CommandLineClass#Command

Defined in:
library/commandline/src/modules/CommandLine.rb

#CommandObject

Get next user-given command

Get next user-given command. If there is a command available, returns it, otherwise ask the user for a command (in interactive mode). Also processes system commands.

@return [Hash] of the new command. If there are no more commands, it returns exit or abort depending on the result user asked for.

@see #Parse



1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
# File 'library/commandline/src/modules/CommandLine.rb', line 1321

def Command
  # if we are done already, return the result
  return { "command" => @aborted ? "abort" : "exit" } if @done

  # there is a command in the cache
  if Builtins.size(@commandcache) != 0
    result = deep_copy(@commandcache)
    @commandcache = {}
    @done = !@interactive
    deep_copy(result)
  # if in interactive mode, ask user for input
  elsif @interactive
    loop do
      newcommand = []
      newcommand = Scan() while Builtins.size(newcommand) == 0

      # EOF reached
      if newcommand.nil?
        @done = true
        return { "command" => "exit" }
      end

      @commandcache = Parse(newcommand)
      break if !ProcessSystemCommands(@commandcache)
      break if @done
    end

    return { "command" => @aborted ? "abort" : "exit" } if @done

    # we are not done, return the command asked back to module
    result = deep_copy(@commandcache)
    @commandcache = {}

    deep_copy(result)
  else
    # there is no further commands left
    @done = true
    { "command" => "exit" }
  end
end