Files
fsh-oop/include/cmd/cmd_touch.hpp

23 lines
617 B
C++

#pragma once
#include "cmd/cmd_base.hpp"
namespace fsh {
class CmdTouch : public Command {
protected:
virtual void register_flags() override {
ArgFactory& factory = get_factory();
factory.add_rule<std::string>(true);
}
virtual void run(std::istream& in, std::ostream& out, ArgManager& args) override {
auto name = *(args.get<std::string>(0));
if (std::ifstream(name, std::ios::in).good() || !std::ofstream(name, std::ios::out).is_open()) {
throw std::runtime_error("File exists");
}
}
};
}