#include "nxtbundlecommand.h"

#include "../nxtremoteprocess.h"

NxtBundleCommand::NxtBundleCommand()
{

}

QString NxtBundleCommand::name() const
{
    return QLatin1String("nxtbundle");
}

int NxtBundleCommand::execute()
{
    QStringList args = arguments();
    for (auto& arg : args)
    {
        if (arg == "nxtbundle")
        {
            arg = "$NXT_FRAMEWORK/bin/nxtbundle.py";
        }
    }

    QStringList commands;
    commands << "source " + environment_setup();
    commands << "export " + nxt_framework();
    commands << args.join(" ");
    QString command = commands.join(" && ");

    NxtRemoteProcess process;
    process.setSshParameters(sshParameters());
    process.setCommand(remotePathMapping(command));
    process.setIntercative(false);
    return process.executeAndWait();
}

bool NxtBundleCommand::isValid() const
{
    return Command::isValid() && !targetName().isEmpty() ;
}
