4 #include "casm/external/gzstream/gzstream.h"
56 err_log <<
"Error parsing query: '" << _args <<
"'" << std::endl;
60 err_log <<
"Check for illegal unescaped characters: |, &, ;, <, >, (, ), {, }" << std::endl;
64 err_log <<
"Check 'man wordexp' for error code meaning" << std::endl;
94 std::vector<std::string> help_commands {
144 auto t = std::time(
nullptr);
146 strftime(str,
sizeof(str),
"%Y-%m-%d %H:%M:%S", std::localtime(&t));
147 return std::string(str);
153 fs::ofstream
log(args.
root /
"LOG", std::ofstream::out | std::ofstream::app);
158 std::string whoami, hostname;
162 fp = popen(
"whoami",
"r");
163 while(fgets(path, PATH_MAX, fp) != NULL) {
164 whoami = std::string(path);
165 whoami.resize(whoami.size() - 1);
171 fp = popen(
"hostname",
"r");
172 while(fgets(path, PATH_MAX, fp) != NULL) {
173 hostname = std::string(path);
174 hostname.resize(hostname.size() - 1);
177 log <<
"# " << whoami <<
"@" << hostname <<
"\n";
180 log <<
"# " <<
version() <<
"\n";
183 for(
int i = 0; i < args.
argc; i++) {
184 log << args.
argv[i] <<
" ";
191 fs::ofstream
log(args.
root /
"LOG", std::ofstream::out | std::ofstream::app);
192 log <<
"# return: " << retcode <<
" runtime(s): " << args.
log.
time_s() <<
"\n\n";
214 int retcode = it->second(args);
271 uniq_primclex.reset(
new PrimClex(args.
root, status_log));
272 return *uniq_primclex;
287 std::ostream &
make_ostream_if(
bool output, std::ostream &sout, std::unique_ptr<std::ostream> &fout,
fs::path out_path,
bool gzip) {
290 if(out_path.string() ==
"STDOUT") {
294 out_path = fs::absolute(out_path);
297 fout.reset(
new gz::ogzstream(out_path.string().c_str()));
301 fout.reset(
new fs::ofstream(out_path));
315 args.
log <<
"casm [--version] <command> [options] [args]" << std::endl << std::endl;
316 args.
log <<
"available commands:" << std::endl;
318 std::vector<std::string> subcom;
320 std::string s = it->first;
323 subcom.push_back(std::string(
" ") + s);
327 std::sort(subcom.begin(), subcom.end());
328 for(
auto it = subcom.begin(); it != subcom.end(); ++it) {
329 args.
log << *it <<
"\n";
333 args.
log <<
"For help using a command: 'casm <command> --help'" << std::endl << std::endl;
334 args.
log <<
"For step by step help use: 'casm status -n'" << std::endl << std::endl;
340 args.
log <<
"casm version: " <<
version() << std::endl;
Data structure holding basic CASM command info.
int update_command(const CommandArgs &args)
int enum_command(const CommandArgs &args)
int rm_command(const CommandArgs &args)
int select_command(const CommandArgs &args)
int files_command(const CommandArgs &args)
int view_command(const CommandArgs &args)
~CommandArgs()
CommandArgs destructor.
int init_command(const CommandArgs &args)
bool m_free_p
Used when parsing std::string args -> argc, argv.
fs::path find_casmroot(const fs::path &cwd)
int super_command(const CommandArgs &args)
int query_command(const CommandArgs &args)
void custom(const std::string &what)
CommandMap & command_map()
Return static CommandMap containing all CASM API commands.
int import_command(const CommandArgs &args)
int status_command(const CommandArgs &args)
int run_command(const CommandArgs &args)
int bset_command(const CommandArgs &args)
PrimClex is the top-level data structure for a CASM project.
int monte_command(const CommandArgs &args)
int ref_command(const CommandArgs &args)
CommandArgs(int _argc, char *_argv[], PrimClex *_primclex, fs::path _root, const Logging &logging)
CommandArgs constructor.
std::map< std::string, Command > CommandMap
std::ostream & make_ostream_if(bool output, std::ostream &sout, std::unique_ptr< std::ostream > &fout, fs::path out_path, bool gzip)
Return a reference to proper std::ostream.
int perturb_command(const CommandArgs &args)
int help_command(const CommandArgs &args)
Print CASM help info to args.log.
void write_LOG_end(const CommandArgs &args, int retcode)
PrimClex & make_primclex_if_not(const CommandArgs &args, std::unique_ptr< PrimClex > &uniq_primclex)
If !_primclex, construct new PrimClex stored in uniq_primclex, then return reference to existing or c...
int sym_command(const CommandArgs &args)
int version_command(const CommandArgs &args)
int format_command(const CommandArgs &args)
const std::string & version()
int parse_result
stores error codes when attempting to parse std::string _args -> argc, argv
bool contains(const Container &container, const T &value)
Equivalent to container.end() != std::find(container.begin(), container.end(), value) ...
int settings_command(const CommandArgs &args)
void write_LOG_begin(const CommandArgs &args)
int casm_api(const CommandArgs &args)
Executes CASM commands specified by args.
int composition_command(const CommandArgs &args)