| 16 | #include "log/log.h" |
| 17 | |
| 18 | FullCommandList::FullCommandList(EgalitoInterface *egalito) { |
| 19 | add(new FunctionCommand("quit", ArgumentSpecList({}, {}), |
| 20 | [] (ShellState &state, ArgumentValueList &args) { |
| 21 | |
| 22 | state.setExiting(true); |
| 23 | return true; |
| 24 | }, "quits the shell")); |
| 25 | add(new FunctionCommand("help", |
| 26 | ArgumentSpecList( |
| 27 | { |
| 28 | {"-l", ArgumentSpec({"-l"}, ArgumentSpec::TYPE_FLAG)} |
| 29 | }, { |
| 30 | ArgumentSpec(ArgumentSpec::TYPE_STRING) |
| 31 | }), |
| 32 | std::bind(&FullCommandList::helpCommand, this, |
| 33 | std::placeholders::_1, std::placeholders::_2), |
| 34 | "prints help about all commands or a specific command")); |
| 35 | add(new FunctionCommand("wc", ArgumentSpecList({}, {}, 0, true), |
| 36 | [] (ShellState &state, ArgumentValueList &args) { |
| 37 | |
| 38 | auto in = args.getInStream(); |
| 39 | long lineCount = 0; |
| 40 | if(in) { |
| 41 | std::string line; |
| 42 | while(std::getline(*in, line)) lineCount ++; |
| 43 | } |
| 44 | (*args.getOutStream()) << std::dec << lineCount << std::endl; |
| 45 | return true; |
| 46 | }, "counts number of lines in input")); |
| 47 | add(new FunctionCommand("head", ArgumentSpecList({ |
| 48 | {"-n", ArgumentSpec({"-n"}, ArgumentSpec::TYPE_DECIMAL)} |
| 49 | }, {}, 0, true), [] (ShellState &state, ArgumentValueList &args) { |
| 50 | |
| 51 | auto in = args.getInStream(); |
| 52 | auto out = args.getOutStream(); |
| 53 | long count = args.getNumber("-n", 10); |
| 54 | std::string line; |
| 55 | for(long i = 0; i < count && std::getline(*in, line); i ++) { |
| 56 | (*out) << line << std::endl; |
| 57 | } |
| 58 | return true; |
| 59 | }, "prints the first N lines of output")); |
| 60 | add(new FunctionCommand("grep", ArgumentSpecList({}, { |
| 61 | ArgumentSpec(ArgumentSpec::TYPE_STRING), |
| 62 | ArgumentSpec(ArgumentSpec::TYPE_STRING), |
| 63 | ArgumentSpec(ArgumentSpec::TYPE_STRING), |
| 64 | ArgumentSpec(ArgumentSpec::TYPE_STRING), |
| 65 | ArgumentSpec(ArgumentSpec::TYPE_STRING), |
| 66 | }, 1, true), std::bind(&FullCommandList::runCommand1, this, |
| 67 | "/bin/grep", std::placeholders::_1, std::placeholders::_2), |
| 68 | "searches input lines for a specified regular expression")); |
| 69 | add(new FunctionCommand("awk", ArgumentSpecList({}, { |
| 70 | ArgumentSpec(ArgumentSpec::TYPE_STRING), |
| 71 | ArgumentSpec(ArgumentSpec::TYPE_STRING), |
| 72 | ArgumentSpec(ArgumentSpec::TYPE_STRING), |
| 73 | ArgumentSpec(ArgumentSpec::TYPE_STRING), |
| 74 | ArgumentSpec(ArgumentSpec::TYPE_STRING), |
| 75 | }, 1, true), std::bind(&FullCommandList::runCommand1, this, |
nothing calls this directly
no test coverage detected