Method: Yast::CommandLineClass#UniqueOption

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

#UniqueOption(options, unique_options) ⇒ Object

Check uniqueness of an option

Check uniqueness of an option. Simply pass the list of user-specified options and a list of mutually exclusive options. In case of error, Report::Error is used.



1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
# File 'library/commandline/src/modules/CommandLine.rb', line 1408

def UniqueOption(options, unique_options)
  return nil if options.nil? || unique_options.nil?

  # sanity check
  if unique_options.empty?
    log.error "Unique list of options required, but the list of the possible options is empty"
    return nil
  end

  # first do a filtering, then convert to a list of keys
  cmds = unique_options & options.keys

  # if it is OK, quickly return
  return cmds.first if cmds.size == 1

  msg = if cmds.empty?
    if unique_options.size == 1
      # translators: error message - missing unique command for command line execution
      Builtins.sformat(_("Specify the command '%1'."), unique_options.first)
    else
      # translators: error message - missing unique command for command line execution
      Builtins.sformat(_("Specify one of the commands: %1."), format_list(unique_options))
    end
  else
    Builtins.sformat(_("Specify only one of the commands: %1."), format_list(cmds))
  end

  Report.Error(msg)
  nil
end