Home | History | Annotate | Download | only in aapt2
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef AAPT_FLAGS_H
     18 #define AAPT_FLAGS_H
     19 
     20 #include "util/Maybe.h"
     21 #include "util/StringPiece.h"
     22 
     23 #include <functional>
     24 #include <ostream>
     25 #include <string>
     26 #include <vector>
     27 
     28 namespace aapt {
     29 
     30 class Flags {
     31 public:
     32     Flags& requiredFlag(const StringPiece& name, const StringPiece& description,
     33                         std::string* value);
     34     Flags& requiredFlagList(const StringPiece& name, const StringPiece& description,
     35                             std::vector<std::string>* value);
     36     Flags& optionalFlag(const StringPiece& name, const StringPiece& description,
     37                         Maybe<std::string>* value);
     38     Flags& optionalFlagList(const StringPiece& name, const StringPiece& description,
     39                             std::vector<std::string>* value);
     40     Flags& optionalSwitch(const StringPiece& name, const StringPiece& description,
     41                           bool* value);
     42 
     43     void usage(const StringPiece& command, std::ostream* out);
     44 
     45     bool parse(const StringPiece& command, const std::vector<StringPiece>& args,
     46                std::ostream* outError);
     47 
     48     const std::vector<std::string>& getArgs();
     49 
     50 private:
     51     struct Flag {
     52         std::string name;
     53         std::string description;
     54         std::function<bool(const StringPiece& value)> action;
     55         bool required;
     56         size_t numArgs;
     57 
     58         bool parsed;
     59     };
     60 
     61     std::vector<Flag> mFlags;
     62     std::vector<std::string> mArgs;
     63 };
     64 
     65 } // namespace aapt
     66 
     67 #endif // AAPT_FLAGS_H
     68