| 778 | } |
| 779 | |
| 780 | void Application::editConfig(const ArgumentOccurrence &) |
| 781 | { |
| 782 | // disable main event loop since this method is invoked directly as argument callback and we're doing all required async operations during the waitForConfig() call already |
| 783 | m_requiresMainEventLoop = false; |
| 784 | |
| 785 | // wait until config is available |
| 786 | const bool viaJavaScript(m_args.script.isPresent() || m_args.jsLines.isPresent()); |
| 787 | if (!(viaJavaScript ? waitForConfigAndStatus() : waitForConfig())) { |
| 788 | return; |
| 789 | } |
| 790 | cerr << Phrases::Override; |
| 791 | |
| 792 | const auto newConfig(viaJavaScript ? editConfigViaScript() : editConfigViaEditor()); |
| 793 | if (newConfig.isEmpty()) { |
| 794 | // just return here; an error message should have already been printed by editConfigVia*() |
| 795 | return; |
| 796 | } |
| 797 | |
| 798 | // handle "dry-run" case |
| 799 | if (m_args.dryRun.isPresent()) { |
| 800 | cout << newConfig.data(); |
| 801 | if (!newConfig.endsWith('\n')) { |
| 802 | cout << '\n'; |
| 803 | } |
| 804 | cout << flush; |
| 805 | return; |
| 806 | } |
| 807 | |
| 808 | // post new config |
| 809 | cerr << Phrases::Info << "Posting new configuration ..." << TextAttribute::Reset << flush; |
| 810 | auto errorConn = signalInfo(&m_connection, &SyncthingConnection::error); |
| 811 | auto newConfigConn = signalInfo(&m_connection, &SyncthingConnection::newConfigTriggered); |
| 812 | if (!waitForSignalsOrFail([this, &newConfig] { m_connection.postConfigFromByteArray(newConfig); }, 0, errorConn, newConfigConn)) { |
| 813 | return; |
| 814 | } |
| 815 | cerr << Phrases::Override << Phrases::Info << "Configuration posted successfully" << Phrases::EndFlush; |
| 816 | } |
| 817 | |
| 818 | QByteArray Application::editConfigViaEditor() const |
| 819 | { |
nothing calls this directly
no test coverage detected