OpenShot Audio Library | OpenShotAudio: juce_ConsoleApplication.h Source File

OpenShot Audio Library | OpenShotAudio 1.0.0

Loading...
Searching...
No Matches
juce_ConsoleApplication.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
38 struct ArgumentList
39{
41 ArgumentList (String executable, StringArray arguments);
42
44 ArgumentList (int argc, char* argv[]);
45
47 ArgumentList (const String& executable, const String& arguments);
48
49 ArgumentList (const ArgumentList&) = default;
50 ArgumentList& operator= (const ArgumentList&) = default;
51
52 //==============================================================================
58 struct Argument
59 {
61 String text;
62
66 File resolveAsFile() const;
67
74 File resolveAsExistingFile() const;
75
82 File resolveAsExistingFolder() const;
83
85 bool isLongOption() const;
86
88 bool isShortOption() const;
89
91 bool isLongOption (const String& optionRoot) const;
92
96 String getLongOptionValue() const;
97
99 bool isShortOption (char shortOptionCharacter) const;
100
102 bool isOption() const;
103
107 bool operator== (StringRef stringToCompare) const;
108
112 bool operator!= (StringRef stringToCompare) const;
113 };
114
115 //==============================================================================
117 int size() const;
118
120 Argument operator[] (int index) const;
121
123 void checkMinNumArguments (int expectedMinNumberOfArgs) const;
124
129 bool containsOption (StringRef option) const;
130
136 bool removeOptionIfFound (StringRef option);
137
141 int indexOfOption (StringRef option) const;
142
144 void failIfOptionIsMissing (StringRef option) const;
145
155 String getValueForOption (StringRef option) const;
156
162 String removeValueForOption (StringRef option);
163
167 File getFileForOption (StringRef option) const;
168
173 File getFileForOptionAndRemove (StringRef option);
174
178 File getExistingFileForOption (StringRef option) const;
179
185 File getExistingFileForOptionAndRemove (StringRef option);
186
190 File getExistingFolderForOption (StringRef option) const;
191
197 File getExistingFolderForOptionAndRemove (StringRef option);
198
200 String executableName;
201
203 Array<Argument> arguments;
204};
205
206
207//==============================================================================
236 struct ConsoleApplication
237{
238 //==============================================================================
246 struct Command
247 {
251 String commandOption;
252
256 String argumentDescription;
257
261 String shortDescription;
262
264 String longDescription;
265
267 std::function<void (const ArgumentList&)> command;
268 };
269
270 //==============================================================================
272 void addCommand (Command);
273
277 void addDefaultCommand (Command);
278
280 void addVersionCommand (String versionArgument, String versionText);
281
286 void addHelpCommand (String helpArgument, String helpMessage, bool makeDefaultCommand);
287
291 void printCommandList (const ArgumentList&) const;
292
296 void printCommandDetails (const ArgumentList&, const Command&) const;
297
298 //==============================================================================
305 static void fail (String errorMessage, int returnCode = 1);
306
311 static int invokeCatchingFailures (std::function<int()>&& functionToCall);
312
313 //==============================================================================
327 int findAndRunCommand (const ArgumentList&,
328 bool optionMustBeFirstArg = false) const;
329
333 int findAndRunCommand (int argc, char* argv[]) const;
334
342 const Command* findCommand (const ArgumentList&, bool optionMustBeFirstArg) const;
343
345 const std::vector<Command>& getCommands() const;
346
347private:
348 //==============================================================================
349 std::vector<Command> commands;
350 int commandIfNoOthersRecognised = -1;
351};
352
353} // 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