Loading...
Searching...
No Matches
juce_ConsoleApplication.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
struct ArgumentList
{
ArgumentList (String executable, StringArray arguments);
ArgumentList (int argc, char* argv[]);
ArgumentList (const String& executable, const String& arguments);
ArgumentList (const ArgumentList&) = default;
ArgumentList& operator= (const ArgumentList&) = default;
//==============================================================================
struct Argument
{
String text;
File resolveAsFile() const;
File resolveAsExistingFile() const;
File resolveAsExistingFolder() const;
bool isLongOption() const;
bool isShortOption() const;
bool isLongOption (const String& optionRoot) const;
String getLongOptionValue() const;
bool isShortOption (char shortOptionCharacter) const;
bool isOption() const;
bool operator== (StringRef stringToCompare) const;
bool operator!= (StringRef stringToCompare) const;
};
//==============================================================================
int size() const;
Argument operator[] (int index) const;
void checkMinNumArguments (int expectedMinNumberOfArgs) const;
bool containsOption (StringRef option) const;
bool removeOptionIfFound (StringRef option);
int indexOfOption (StringRef option) const;
void failIfOptionIsMissing (StringRef option) const;
String getValueForOption (StringRef option) const;
String removeValueForOption (StringRef option);
File getFileForOption (StringRef option) const;
File getFileForOptionAndRemove (StringRef option);
File getExistingFileForOption (StringRef option) const;
File getExistingFileForOptionAndRemove (StringRef option);
File getExistingFolderForOption (StringRef option) const;
File getExistingFolderForOptionAndRemove (StringRef option);
String executableName;
Array<Argument> arguments;
};
//==============================================================================
struct ConsoleApplication
{
//==============================================================================
struct Command
{
String commandOption;
String argumentDescription;
String shortDescription;
String longDescription;
std::function<void (const ArgumentList&)> command;
};
//==============================================================================
void addCommand (Command);
void addDefaultCommand (Command);
void addVersionCommand (String versionArgument, String versionText);
void addHelpCommand (String helpArgument, String helpMessage, bool makeDefaultCommand);
void printCommandList (const ArgumentList&) const;
void printCommandDetails (const ArgumentList&, const Command&) const;
//==============================================================================
static void fail (String errorMessage, int returnCode = 1);
static int invokeCatchingFailures (std::function<int()>&& functionToCall);
//==============================================================================
int findAndRunCommand (const ArgumentList&,
bool optionMustBeFirstArg = false) const;
int findAndRunCommand (int argc, char* argv[]) const;
const Command* findCommand (const ArgumentList&, bool optionMustBeFirstArg) const;
const std::vector<Command>& getCommands() const;
private:
//==============================================================================
std::vector<Command> commands;
int commandIfNoOthersRecognised = -1;
};
} // namespace juce
juce::Array
Definition juce_Array.h:56
juce::File
Definition juce_File.h:45
juce::StringArray
Definition juce_StringArray.h:35
juce::StringRef
Definition juce_StringRef.h:62
juce::String
Definition juce_String.h:53
juce::ArgumentList::Argument
Definition juce_ConsoleApplication.h:59
juce::ArgumentList::Argument::operator!=
bool operator!=(StringRef stringToCompare) const
Definition juce_ConsoleApplication.cpp:134
juce::ArgumentList::Argument::resolveAsExistingFile
File resolveAsExistingFile() const
Definition juce_ConsoleApplication.cpp:63
juce::ArgumentList::Argument::text
String text
Definition juce_ConsoleApplication.h:61
juce::ArgumentList::Argument::isLongOption
bool isLongOption() const
Definition juce_ConsoleApplication.cpp:82
juce::ArgumentList::Argument::resolveAsExistingFolder
File resolveAsExistingFolder() const
Definition juce_ConsoleApplication.cpp:68
juce::ArgumentList::Argument::isShortOption
bool isShortOption() const
Definition juce_ConsoleApplication.cpp:83
juce::ArgumentList::Argument::resolveAsFile
File resolveAsFile() const
Definition juce_ConsoleApplication.cpp:58
juce::ArgumentList::Argument::operator==
bool operator==(StringRef stringToCompare) const
Definition juce_ConsoleApplication.cpp:117
juce::ArgumentList::Argument::getLongOptionValue
String getLongOptionValue() const
Definition juce_ConsoleApplication.cpp:97
juce::ArgumentList::Argument::isOption
bool isOption() const
Definition juce_ConsoleApplication.cpp:84
juce::ArgumentList
Definition juce_ConsoleApplication.h:39
juce::ArgumentList::getExistingFileForOptionAndRemove
File getExistingFileForOptionAndRemove(StringRef option)
Definition juce_ConsoleApplication.cpp:274
juce::ArgumentList::removeValueForOption
String removeValueForOption(StringRef option)
Definition juce_ConsoleApplication.cpp:224
juce::ArgumentList::getExistingFileForOption
File getExistingFileForOption(StringRef option) const
Definition juce_ConsoleApplication.cpp:269
juce::ArgumentList::removeOptionIfFound
bool removeOptionIfFound(StringRef option)
Definition juce_ConsoleApplication.cpp:182
juce::ArgumentList::getExistingFolderForOption
File getExistingFolderForOption(StringRef option) const
Definition juce_ConsoleApplication.cpp:279
juce::ArgumentList::indexOfOption
int indexOfOption(StringRef option) const
Definition juce_ConsoleApplication.cpp:166
juce::ArgumentList::executableName
String executableName
Definition juce_ConsoleApplication.h:200
juce::ArgumentList::getFileForOption
File getFileForOption(StringRef option) const
Definition juce_ConsoleApplication.cpp:259
juce::ArgumentList::failIfOptionIsMissing
void failIfOptionIsMissing(StringRef option) const
Definition juce_ConsoleApplication.cpp:192
juce::ArgumentList::arguments
Array< Argument > arguments
Definition juce_ConsoleApplication.h:203
juce::ArgumentList::containsOption
bool containsOption(StringRef option) const
Definition juce_ConsoleApplication.cpp:177
juce::ArgumentList::checkMinNumArguments
void checkMinNumArguments(int expectedMinNumberOfArgs) const
Definition juce_ConsoleApplication.cpp:160
juce::ArgumentList::getValueForOption
String getValueForOption(StringRef option) const
Definition juce_ConsoleApplication.cpp:198
juce::ArgumentList::operator[]
Argument operator[](int index) const
Definition juce_ConsoleApplication.cpp:158
juce::ArgumentList::size
int size() const
Definition juce_ConsoleApplication.cpp:157
juce::ArgumentList::ArgumentList
ArgumentList(String executable, StringArray arguments)
Definition juce_ConsoleApplication.cpp:137
juce::ArgumentList::getFileForOptionAndRemove
File getFileForOptionAndRemove(StringRef option)
Definition juce_ConsoleApplication.cpp:264
juce::ArgumentList::getExistingFolderForOptionAndRemove
File getExistingFolderForOptionAndRemove(StringRef option)
Definition juce_ConsoleApplication.cpp:284
juce::ConsoleApplication
Definition juce_ConsoleApplication.h:237
juce::ConsoleApplication::printCommandDetails
void printCommandDetails(const ArgumentList &, const Command &) const
Definition juce_ConsoleApplication.cpp:428
juce::ConsoleApplication::findAndRunCommand
int findAndRunCommand(const ArgumentList &, bool optionMustBeFirstArg=false) const
Definition juce_ConsoleApplication.cpp:334
juce::ConsoleApplication::addDefaultCommand
void addDefaultCommand(Command)
Definition juce_ConsoleApplication.cpp:357
juce::ConsoleApplication::Command::argumentDescription
String argumentDescription
Definition juce_ConsoleApplication.h:256
juce::ConsoleApplication::printCommandList
void printCommandList(const ArgumentList &) const
Definition juce_ConsoleApplication.cpp:413
juce::ConsoleApplication::Command::commandOption
String commandOption
Definition juce_ConsoleApplication.h:251
juce::ConsoleApplication::findCommand
const Command * findCommand(const ArgumentList &, bool optionMustBeFirstArg) const
Definition juce_ConsoleApplication.cpp:318
juce::ConsoleApplication::addCommand
void addCommand(Command)
Definition juce_ConsoleApplication.cpp:352
juce::ConsoleApplication::Command::command
std::function< void(const ArgumentList &)> command
Definition juce_ConsoleApplication.h:267
juce::ConsoleApplication::invokeCatchingFailures
static int invokeCatchingFailures(std::function< int()> &&functionToCall)
Definition juce_ConsoleApplication.cpp:301
juce::ConsoleApplication::addHelpCommand
void addHelpCommand(String helpArgument, String helpMessage, bool makeDefaultCommand)
Definition juce_ConsoleApplication.cpp:363
juce::ConsoleApplication::addVersionCommand
void addVersionCommand(String versionArgument, String versionText)
Definition juce_ConsoleApplication.cpp:378
juce::ConsoleApplication::Command::shortDescription
String shortDescription
Definition juce_ConsoleApplication.h:261
juce::ConsoleApplication::fail
static void fail(String errorMessage, int returnCode=1)
Definition juce_ConsoleApplication.cpp:296
juce::ConsoleApplication::getCommands
const std::vector< Command > & getCommands() const
Definition juce_ConsoleApplication.cpp:387
juce::ConsoleApplication::Command::longDescription
String longDescription
Definition juce_ConsoleApplication.h:264
juce::ConsoleApplication::Command
Definition juce_ConsoleApplication.h:247