3 #include <boost/filesystem.hpp>
4 #include <boost/filesystem/fstream.hpp>
31 #include "casm/external/gzstream/gzstream.h"
38 out <<
" .::::::::. .:::::. .::::::. .:. "
40 <<
" .:::::::::::. .:::::::. .::::::::::. .:::. "
42 <<
" .:::' ':::. .:::' ':::. .:::' ':::: .:::::. "
44 <<
" :::: :::: .:::' ':::. :::: '::' .:::::::. "
46 <<
" :::: :::: :::: '::::. "
47 "::::'':::.:::'':::: \n"
48 <<
" :::: :::: :::: '::::::. :::: "
50 <<
" :::: ::::::::::::: ''::::::. :::: ':::' "
52 <<
" :::: ::::::::::::: ':::::: :::: ':' "
54 <<
" :::: .:::: :::: :::: ::::: :::: "
56 <<
" ':::. .::::' :::: :::: .::. .:::: :::: "
58 <<
" '::::::::::' :::: :::: :::::...:::::' :::: "
60 <<
" ':::::' '::' '::' ':::::::::::' '::' "
106 std::vector<std::string> help_commands{
107 "help",
"-h",
"--help",
"version",
"--version",
"status",
"format"};
121 {
"info", run_api_command<InfoCommand>},
130 {
"bset", run_api_command<BsetCommand>},
146 auto t = std::time(
nullptr);
148 strftime(str,
sizeof(str),
"%Y-%m-%d %H:%M:%S", std::localtime(&t));
149 return std::string(str);
154 fs::ofstream
log(args.
root /
"LOG", std::ofstream::out | std::ofstream::app);
159 std::string whoami, hostname;
163 fp = popen(
"whoami",
"r");
164 while (fgets(path, PATH_MAX, fp) != NULL) {
165 whoami = std::string(path);
166 whoami.resize(whoami.size() - 1);
172 fp = popen(
"hostname",
"r");
173 while (fgets(path, PATH_MAX, fp) != NULL) {
174 hostname = std::string(path);
175 hostname.resize(hostname.size() - 1);
178 log <<
"# " << whoami <<
"@" << hostname <<
"\n";
184 for (
int i = 0; i < args.
argc(); i++) {
192 fs::ofstream
log(args.
root /
"LOG", std::ofstream::out | std::ofstream::app);
202 if (args.
argc() == 1) {
214 int retcode = it->second(args);
236 std::unique_ptr<PrimClex> &uniq_primclex) {
239 return *uniq_primclex;
255 std::unique_ptr<std::ostream> &fout,
256 fs::path out_path,
bool gzip) {
258 if (out_path.string() ==
"STDOUT") {
262 out_path = fs::absolute(out_path);
265 fout.reset(
new gz::ogzstream(out_path.string().c_str()));
269 fout.reset(
new fs::ofstream(out_path));
281 log() <<
"casm [--version] <command> [options] [args]" << std::endl
283 log() <<
"available commands:" << std::endl;
285 std::vector<std::string> subcom;
287 std::string
s = it->first;
290 subcom.push_back(std::string(
" ") +
s);
294 std::sort(subcom.begin(), subcom.end());
295 for (
auto it = subcom.begin(); it != subcom.end(); ++it) {
296 log() << *it <<
"\n";
300 log() <<
"For help using a command: 'casm <command> --help'" << std::endl
302 log() <<
"For step by step help use: 'casm status -n'" << std::endl
309 log() <<
"casm version: " <<
version() << std::endl;
std::set< std::string > & s
static const std::string name
static const std::string name
void custom(const std::string &what)
PrimClex is the top-level data structure for a CASM project.
static const std::string name
static const std::string name
static const std::string name
static const std::string name
static const std::string name
CommandMap & command_map()
Return static CommandMap containing all CASM API commands.
int version_command(const CommandArgs &args)
int help_command(const CommandArgs &args)
Print CASM help info to log()
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.
std::map< std::string, Command > CommandMap
int casm_api(const CommandArgs &args)
Executes CASM commands specified by args.
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...
void write_LOG_begin(const CommandArgs &args)
void write_LOG_end(const CommandArgs &args, int retcode)
int format_command(const CommandArgs &args)
int view_command(const CommandArgs &args)
void print_splash(std::ostream &out)
int files_command(const CommandArgs &args)
fs::path find_casmroot(const fs::path &cwd)
int super_command(const CommandArgs &args)
int status_command(const CommandArgs &args)
int run_command(const CommandArgs &args)
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)
const std::string & version()
int init_command(const CommandArgs &args)
int monte_command(const CommandArgs &args)
int ref_command(const CommandArgs &args)
int composition_command(const CommandArgs &args)
Data structure holding basic CASM command info.
CommandArgs(int _argc, char *_argv[], PrimClex *_primclex=nullptr, fs::path _root=fs::path())
CommandArgs constructor.
~CommandArgs()
CommandArgs destructor.