Finished Batch + Minor improvements
This commit is contained in:
29
include/cmd/cmd_head.hpp
Normal file
29
include/cmd/cmd_head.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "cmd/cmd_base.hpp"
|
||||
|
||||
namespace fsh {
|
||||
|
||||
class CmdHead : public Command {
|
||||
|
||||
protected:
|
||||
virtual void register_flags() override {
|
||||
ArgFactory& factory = get_factory();
|
||||
factory.add_rule<int>((std::string) "-n", true);
|
||||
factory.add_input_rule();
|
||||
}
|
||||
|
||||
virtual void run(std::istream& in, std::ostream& out, ArgManager& args) override {
|
||||
std::string s;
|
||||
std::string o;
|
||||
|
||||
int count = args.get<int>("-n").value();
|
||||
while (std::getline(in, s)) {
|
||||
if(count-- < 1) break;
|
||||
o += s + "\n";
|
||||
}
|
||||
out << o;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user