From 1b8eb3b19a8793fb225bdc785ebc10bea63bbb36 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 1 Nov 2017 23:28:08 +0100 Subject: Ensure we get a return code --- sinksh/syntax_modules/sink_list.cpp | 6 ++---- sinksh/syntaxtree.cpp | 3 +++ sinksh/syntaxtree.h | 11 ++++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index 7421b89..e4c4837 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp @@ -169,14 +169,12 @@ bool list(const QStringList &args_, State &state) } } state.flushTable(); - state.commandFinished(); - - return false; + return true; } Syntax::List syntax() { - Syntax list("list", QObject::tr("List all resources, or the contents of one or more resources."), &SinkList::list, Syntax::EventDriven); + Syntax list("list", QObject::tr("List all resources, or the contents of one or more resources."), &SinkList::list, Syntax::NotInteractive); list.completer = &SinkshUtils::resourceOrTypeCompleter; return Syntax::List() << list; } diff --git a/sinksh/syntaxtree.cpp b/sinksh/syntaxtree.cpp index 65eb769..0eb9782 100644 --- a/sinksh/syntaxtree.cpp +++ b/sinksh/syntaxtree.cpp @@ -68,6 +68,9 @@ int SyntaxTree::run(const QStringList &commands) if (success && command.first->interactivity == Syntax::EventDriven) { returnCode = m_state.commandStarted(); } + if (!success && command.first->interactivity != Syntax::EventDriven) { + returnCode = 1; + } } else if (command.first->children.isEmpty()) { m_state.printError(QObject::tr("Broken command... sorry :("), "st_broken"); } else { diff --git a/sinksh/syntaxtree.h b/sinksh/syntaxtree.h index 8fbbd01..ce28548 100644 --- a/sinksh/syntaxtree.h +++ b/sinksh/syntaxtree.h @@ -45,7 +45,16 @@ public: QString keyword; QString help; Interactivity interactivity; - std::function lambda; + + /** + * This function will be called to execute the command. + * + * @arguments: The command arguments + * @state: The state object + * @return: Return true for success and false for error. If the command is event driven, returning false will not start an event loop and abort immediately. + * If the command is not event driven, returning false will set the exit code to 1. + */ + std::function lambda; std::function completer; QVector children; -- cgit v1.2.3