#include "nfileinfo.h"
#include "nobject.h"
#include "nstring.h"
#include "ngetopt.h"
#include "noutput.h"
class FileInfoApp {
public:
FileInfoApp(void) {
}
bool setFile(const NOpt<FileInfoApp> &opt) {
m_filename = opt.getValues().at(0);
return true;
}
int run(void) {
NFileInfo info(m_filename);
NMessage::print() << "The file " << m_filename <<
(info.isFile() ? " is" : " is not") << " a file";
NMessage::print() << "The file " << m_filename <<
(info.isDir() ? " is" : " is not") <<
" a directory";
NMessage::print() << "The file " << m_filename <<
(info.isDevice() ? " is" : " is not") <<
" a device";
NMessage::print() << "The file " << m_filename <<
(info.isFifo() ? " is" : " is not") << " a fifo";
NMessage::print() << "The file " << m_filename <<
(info.isLink() ? " is" : " is not") << " a link";
NMessage::print() << "The file " << m_filename <<
(info.ownerRead() ? " can" : " can not") <<
" be read by the owner";
NMessage::print() << "The file " << m_filename <<
(info.groupRead() ? " can" : " can not") <<
" be read by the group";
NMessage::print() << "The file " << m_filename <<
(info.othersRead() ? " can" : " can not") <<
" be read by others";
NMessage::print() << "The file " << m_filename <<
(info.ownerWrite() ? " can" : " can not") <<
" be written by the owner";
NMessage::print() << "The file " << m_filename <<
(info.groupWrite() ? " can" : " can not") <<
" be written by the group";
NMessage::print() << "The file " << m_filename <<
(info.othersWrite() ? " can" : " can not") <<
" be written by others";
NMessage::print() << "The file " << m_filename <<
(info.ownerExecute() ? " can" : " can not") <<
" be executed by the owner";
NMessage::print() << "The file " << m_filename <<
(info.groupExecute() ? " can" : " can not") <<
" be executed by the group";
NMessage::print() << "The file " << m_filename <<
(info.othersExecute() ? " can" : " can not") <<
" be executed by others";
return 0;
}
private:
NString m_filename;
};
void setup_opts(NGetOpt<FileInfoApp> *opts) {
opts->add("h", "help", false, "Display the help for this program", NULL);
opts->add("f", "file", true, "The file/directory to check",
&FileInfoApp::setFile);
}
int main(int argc, char **argv) {
FileInfoApp app;
NGetOpt<FileInfoApp> opts(argc, argv, &app, 1);
setup_opts(&opts);
try {
if (opts.proccess()) {
app.run();
}
}
catch (NException &e) {
NWarning::print() << e.getDescription();
exit(1);
}
return 0;
}