OpenShot Audio Library | OpenShotAudio  0.3.0
juce_ConsoleApplication.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2017 - ROLI Ltd.
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 
23 namespace juce
24 {
25 
26 //==============================================================================
39 {
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  {
62 
66  File resolveAsFile() const;
67 
75 
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 
163 
167  File getFileForOption (StringRef option) const;
168 
174 
178  File getExistingFileForOption (StringRef option) const;
179 
186 
191 
198 
201 
204 };
205 
206 
207 //==============================================================================
237 {
238  //==============================================================================
246  struct Command
247  {
252 
257 
262 
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 
347 private:
348  //==============================================================================
349  std::vector<Command> commands;
350  int commandIfNoOthersRecognised = -1;
351 };
352 
353 } // namespace juce
bool operator!=(StringRef stringToCompare) const
bool operator==(StringRef stringToCompare) const
File getExistingFileForOptionAndRemove(StringRef option)
String removeValueForOption(StringRef option)
File getExistingFileForOption(StringRef option) const
bool removeOptionIfFound(StringRef option)
File getExistingFolderForOption(StringRef option) const
int indexOfOption(StringRef option) const
File getFileForOption(StringRef option) const
void failIfOptionIsMissing(StringRef option) const
Array< Argument > arguments
bool containsOption(StringRef option) const
void checkMinNumArguments(int expectedMinNumberOfArgs) const
String getValueForOption(StringRef option) const
Argument operator[](int index) const
ArgumentList(String executable, StringArray arguments)
File getFileForOptionAndRemove(StringRef option)
File getExistingFolderForOptionAndRemove(StringRef option)
void printCommandDetails(const ArgumentList &, const Command &) const
int findAndRunCommand(const ArgumentList &, bool optionMustBeFirstArg=false) const
void printCommandList(const ArgumentList &) const
const Command * findCommand(const ArgumentList &, bool optionMustBeFirstArg) const
std::function< void(const ArgumentList &)> command
static int invokeCatchingFailures(std::function< int()> &&functionToCall)
void addHelpCommand(String helpArgument, String helpMessage, bool makeDefaultCommand)
void addVersionCommand(String versionArgument, String versionText)
static void fail(String errorMessage, int returnCode=1)
const std::vector< Command > & getCommands() const