Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 795b6ec8 authored by Yifan Hong's avatar Yifan Hong
Browse files

lshal: Lshal register commands

Register commands to the controller class Lshal to autogenerate
help messages and select the correct Command.

Test: lshal_test
Change-Id: I846aef13d77bcee328c8410dc61f2e8b4c0e0d69
parent a8bedc6a
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -35,6 +35,12 @@ public:

    virtual void usage() const = 0;

    // e.g. "list"
    virtual std::string getName() const = 0;

    // e.g. "list HALs"
    virtual std::string getSimpleDescription() const = 0;

protected:
    Lshal& mLshal;
};
+8 −0
Original line number Diff line number Diff line
@@ -21,6 +21,14 @@
namespace android {
namespace lshal {

std::string DebugCommand::getName() const {
    return "debug";
}

std::string DebugCommand::getSimpleDescription() const {
    return "Debug a specified HAL.";
}

Status DebugCommand::parseArgs(const Arg &arg) {
    if (optind >= arg.argc) {
        return USAGE;
+2 −0
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ public:
    ~DebugCommand() = default;
    Status main(const Arg &arg) override;
    void usage() const override;
    std::string getSimpleDescription() const override;
    std::string getName() const override;
private:
    Status parseArgs(const Arg &arg);

+18 −11
Original line number Diff line number Diff line
@@ -21,6 +21,14 @@
namespace android {
namespace lshal {

std::string HelpCommand::GetName() {
    return "help";
}

std::string HelpCommand::getSimpleDescription() const {
    return "Print help message.";
}

Status HelpCommand::main(const Arg &arg) {
    if (optind >= arg.argc) {
        // `lshal help` prints global usage.
@@ -49,18 +57,17 @@ Status HelpCommand::usageOfCommand(const std::string& c) const {
}

void HelpCommand::usage() const {
    static const std::string help =
            "help:\n"
            "    lshal -h\n"
            "    lshal --help\n"
            "    lshal help\n"
            "        Print this help message\n"
            "    lshal help list\n"
            "        Print help message for list\n"
            "    lshal help debug\n"
            "        Print help message for debug\n";
    mLshal.err()
            << "help:" << std::endl
            << "    lshal -h" << std::endl
            << "    lshal --help" << std::endl
            << "    lshal help" << std::endl
            << "        Print this help message" << std::endl;
    mLshal.forEachCommand([&](const Command* e) {
        mLshal.err() << "    lshal help " << e->getName() << std::endl
                     << "        Print help message for " << e->getName() << std::endl;
    });

    mLshal.err() << help;
}

}  // namespace lshal
+3 −0
Original line number Diff line number Diff line
@@ -35,6 +35,9 @@ public:
    ~HelpCommand() = default;
    Status main(const Arg &arg) override;
    void usage() const override;
    std::string getSimpleDescription() const override;
    std::string getName() const override { return GetName(); }
    static std::string GetName();
    Status usageOfCommand(const std::string& c) const;
};

Loading