| 404 | } |
| 405 | |
| 406 | int CLI::execute() |
| 407 | { |
| 408 | m_parser.process(*m_app); |
| 409 | |
| 410 | // Check for version flag |
| 411 | if (m_parser.isSet("version")) { |
| 412 | printVersion(); |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | // Check privileges |
| 417 | if (!qefi_has_privilege()) { |
| 418 | QTextStream err(stderr); |
| 419 | err << "Error: Insufficient privileges. Please run as root or with elevated privileges." << Qt::endl; |
| 420 | return 1; |
| 421 | } |
| 422 | |
| 423 | #ifndef QT_NO_DEBUG |
| 424 | // Test scan option might need privileges but not EFI |
| 425 | if (m_parser.isSet("test-scan")) { |
| 426 | return runPartitionScanTest(); |
| 427 | } |
| 428 | #endif |
| 429 | |
| 430 | // Check EFI availability and privileges |
| 431 | if (!qefi_is_available()) { |
| 432 | QTextStream err(stderr); |
| 433 | err << "Error: No EFI environment available" << Qt::endl; |
| 434 | return 1; |
| 435 | } |
| 436 | |
| 437 | // Load boot entries |
| 438 | QEFIEntryStaticList *list = QEFIEntryStaticList::instance(); |
| 439 | list->load(); |
| 440 | |
| 441 | // Handle modifications first |
| 442 | bool hasModifications = m_parser.isSet("active") || m_parser.isSet("inactive") || m_parser.isSet("delete-bootnum") || m_parser.isSet("bootorder") |
| 443 | || m_parser.isSet("delete-bootorder") || m_parser.isSet("bootnext") || m_parser.isSet("delete-bootnext") || m_parser.isSet("timeout") |
| 444 | || m_parser.isSet("delete-timeout") || m_parser.isSet("remove-dups") || m_parser.isSet("create") || m_parser.isSet("create-only"); |
| 445 | |
| 446 | if (hasModifications) { |
| 447 | if (!handleModifications()) { |
| 448 | return 1; |
| 449 | } |
| 450 | // Reload to show updated state |
| 451 | list->load(); |
| 452 | } |
| 453 | |
| 454 | // Print boot entries (default behavior or after modifications) |
| 455 | bool verbose = m_parser.isSet("verbose"); |
| 456 | bool quiet = m_parser.isSet("quiet"); |
| 457 | printBootEntries(verbose, quiet); |
| 458 | |
| 459 | return 0; |
| 460 | } |
no test coverage detected