Added Include folder
*facepalm*
This commit is contained in:
34
include/cmd/cmd_truncate.hpp
Normal file
34
include/cmd/cmd_truncate.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "cmd/cmd_base.hpp"
|
||||
#include <fstream>
|
||||
#include <ios>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace fsh {
|
||||
|
||||
class CmdTruncate : public Command {
|
||||
|
||||
protected:
|
||||
virtual void register_flags() override {
|
||||
ArgFactory& factory = get_factory();
|
||||
factory.add_rule<std::string>(1);
|
||||
}
|
||||
|
||||
virtual void run(std::istream& in, std::ostream& out, ArgManager& args) override {
|
||||
|
||||
std::string filename = args.get<std::string>(0).value();
|
||||
|
||||
if(!std::ifstream(filename, std::ios_base::in)) {
|
||||
throw std::runtime_error("File does not exist");
|
||||
}
|
||||
|
||||
if(!std::ofstream(filename, std::ios_base::out)) {
|
||||
throw std::runtime_error("Failed to truncate");
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user