From af5f5fd1157e3e49174c452e04cf74608d6a7e5c Mon Sep 17 00:00:00 2001 From: My Name <my-name@chromium.org> Date: Sat, 18 Jan 2025 16:09:26 +0100 Subject: [PATCH] Added new command --- .vscode/settings.json | 3 ++- README.md | 6 +++-- nosh.cpp | 54 +++++++++++++++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 3b51143..fdb31cf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "files.associations": { "vector": "cpp", - "deque": "cpp" + "deque": "cpp", + "iostream": "cpp" } } \ No newline at end of file diff --git a/README.md b/README.md index 485b0e2..11531ee 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,9 @@ Nosh is a simple, customizable command-line shell designed for Windows systems. `noemi`: Draw a heart shape made of # characters. `noemi -l`: Draw a heart shape made of # characters with more delay. -| + +`now`: Gets and prints out the current date and tame. + `rn (rename)`: Rename a file or directory. Usage: `rn <old_name> <new_name>`. `store`: Save a string of maximum 100 characters during runtime. @@ -72,7 +74,7 @@ Before contributing, please note that if you create a derivative or customized v ```` MIT License -Copyright (c) 2025 Zsombor Szabó-Antalovszky +Copyright (C) 2025 Zsombor Szabó-Antalovszky Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, subject to the following conditions: diff --git a/nosh.cpp b/nosh.cpp index ef4e7b6..7d2d6b4 100644 --- a/nosh.cpp +++ b/nosh.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2025 Zsombor Szabó-Antalovszky + * Copyright (C) 2025 Zsombor Szabó-Antalovszky * * ------------------------------------------------------------------------------------------------------------------- * Dear future programmer, @@ -29,11 +29,9 @@ * * CHANGELOG * - * Noémi Shell v.0.4 + * Noémi Shell ver. 0.3.3 * - * This version introduces the 'exec' command for executing executable files. - * Exec is using the system command via the Windows API. This version also changed the 'store get' - * command to 'store -g' for improved standardization. + * This version introduces the new 'now' command that prints out the current date and time. * */ @@ -49,7 +47,8 @@ #include <cstdlib> #include <deque> -const char VERSION[] = "0.3.2"; ///< Change version number here for the entire code +const char VERSION[] = "0.3.3"; ///< Change version number here for the entire code + #define STRLEN 100 ///< Max string length #define WIDTH 10 ///< Width between columns @@ -73,14 +72,15 @@ void handle_crush(const vector<string>& args); void handle_mkdir(const vector<string>& args); void handle_rn(const vector<string>& args); void handle_exec(const vector<string>& args); +void handle_help(const vector<string>& args); +void handle_now(const vector<string>& args); /** * The main function */ - int main() { - cout << "Noemi Shell (nosh)\n" + cout << "Noemi Shell (nosh) ver. " << VERSION << "\n" << "Copyright (C) 2025 Zsombor Szabo-Antalovszky\n\n" << "Type 'help' or '? for list of available commands\n\n"; @@ -160,6 +160,7 @@ void handle_help(const vector<string>& args){ << "mkdir: Create a new directory whithin current directory\n" << "noemi: Draw a heart shape made of # characters\n" << "noemi -l: Draw a heart shape made of # characters with more delay\n" + << "now: Gets and prints out the curent date and time\n" << "rn: rename a file or a directory\n" << "store: Save a string of maximum 100 characters during runtime\n" << "store -g: Show the string saved with store\n\n"; @@ -181,6 +182,29 @@ void handle_exec(const vector<string>& args){ system(path.c_str()); // Runs the executable } +/** + * Gets and prints out the current date + * + * @param args for arguments + */ +void handle_now(const vector<string>& args){ + + // If arguments exist + if (args.size() > 2){ + cout << "now: too many arguments\n"; + return; + } + + + // Set timestamp + time_t timestamp; + time(×tamp); + + // Print out date and time + cout << "\n" << ctime(×tamp) << "\n"; +} + + /** * Handling the 'pwd' command for printing the working directory * @@ -224,7 +248,7 @@ bool is_builtin_command(const vector<string>& args){ if (args.size() == 2) { if (args[1] == "--version"){ - cout << "v" << VERSION; + cout << "ver. " << VERSION; cout << "\n"; return true; } @@ -234,9 +258,10 @@ bool is_builtin_command(const vector<string>& args){ } } - cout << "\nNoemi Shell v" << VERSION; - cout << "\n"; - cout << "Copyright (C) 2025 Zsombor Szabo-Antalovszky \n" << endl; + cout << "\nNoemi Shell (nosh) ver. " << VERSION << "\n" + << "Copyright (C) 2025 Zsombor Szabo-Antalovszky\n\n" + << "Type 'help' or '? for list of available commands\n\n"; + return true; } @@ -326,6 +351,11 @@ bool is_builtin_command(const vector<string>& args){ return true; } + if (args[0] == "now"){ + handle_now(args); + return true; + } + return false; // Return false if given command does not exist } -- GitLab