summaryrefslogtreecommitdiffstats
path: root/source/core/slang-command-line.cpp
blob: 419c031ab92165dec35e470948979b252e202520 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// slang-command-line.cpp
#include "slang-command-line.h"

#include "slang-process.h"

#include "slang-string.h"
#include "slang-string-escape-util.h"
#include "slang-string-util.h"

#include "../../slang-com-helper.h"

namespace Slang {

void CommandLine::addPrefixPathArg(const char* prefix, const String& path, const char* pathPostfix)
{
    StringBuilder builder;
    builder << prefix << path;
    if (pathPostfix)
    {
        // Work out the path with the postfix
        builder << pathPostfix;
    }
    addArg(builder.ProduceString());
}

void CommandLine::setExecutable(const String& dir, const String& name)
{
    StringBuilder builder;
    Path::combineIntoBuilder(dir.getUnownedSlice(), name.getUnownedSlice(), builder);
    builder << Process::getExecutableSuffix();
    setExecutablePath(builder.ProduceString());
}

void CommandLine::append(StringBuilder& out) const
{
    auto escapeHandler = Process::getEscapeHandler();

    StringEscapeUtil::appendMaybeQuoted(escapeHandler, m_executable.getUnownedSlice(), out);

    for (const auto& arg : m_args)
    {
        out << " ";
        StringEscapeUtil::appendMaybeQuoted(escapeHandler, arg.getUnownedSlice(), out);
    }
}

String CommandLine::toString() const
{
    StringBuilder buf;
    append(buf);
    return buf.ProduceString();
}

} // namespace Slang