├── .gitattributes ├── .github └── FUNDING.yml ├── Code ├── cli.cpp └── cli.out ├── LICENSE └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://www.cyfylabs.com'] 13 | -------------------------------------------------------------------------------- /Code/cli.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | bool cont = true; 12 | 13 | char buffer[100] = {}; 14 | 15 | while (cont) 16 | { 17 | cout << "\n\nEnter a command: "; 18 | 19 | cin.get (buffer, 90); 20 | 21 | //REMOVE 22 | if (strstr (buffer,"remove") != NULL) 23 | { 24 | char* t = strchr (buffer,' '); 25 | 26 | if(t != NULL) 27 | { 28 | if(remove( t+1 ) != 0) 29 | cout << "\n\nError deleting the file."; 30 | else 31 | cout << "\n\nThe file has successfully been deleted."; 32 | } 33 | 34 | else 35 | cout << "\n\nInvalid command. Filename not entered."; 36 | 37 | } 38 | 39 | //EXIT 40 | else if (strstr (buffer,"exit") != NULL) 41 | cont = false; 42 | 43 | 44 | //RENAME 45 | else if (strstr (buffer,"rename") != NULL) 46 | { 47 | char* t = strchr (buffer,' '); 48 | 49 | if (t != NULL) 50 | { 51 | char* oldName = t + 1; 52 | char* newName = strchr (oldName, ' '); 53 | 54 | 55 | if (newName != NULL) 56 | { 57 | char temp[30] = {}; 58 | 59 | int i = 0; 60 | for(char* start = oldName; start != newName; start++) 61 | { 62 | temp[i] = *start; 63 | i++; 64 | } 65 | 66 | newName++; 67 | 68 | 69 | if(rename( temp , newName ) != 0) 70 | cout << "\nError renaming the file."; 71 | else 72 | cout << "\nThe file has successfully been renamed."; 73 | } 74 | 75 | else 76 | cout << "\n\nNew Name of the file not entered."; 77 | } 78 | 79 | else 80 | cout << "\n\nInvalid command."; 81 | 82 | } 83 | 84 | 85 | //RMDIR 86 | else if (strstr (buffer,"rmdir") != NULL) 87 | { 88 | char* t = strchr (buffer,' '); 89 | 90 | if(t != NULL) 91 | { 92 | if(rmdir( t+1 ) != 0) 93 | cout << "\n\nError deleting the directory."; 94 | else 95 | cout << "\n\nThe directory has successfully been removed."; 96 | } 97 | 98 | else 99 | cout << "\n\nInvalid command. DirectoryName not entered."; 100 | 101 | } 102 | 103 | 104 | //ECHO 105 | else if (strstr (buffer,"echo") != NULL) 106 | { 107 | char* t = strchr (buffer,'"'); 108 | 109 | if (t != NULL) 110 | { 111 | char* data = t + 1; 112 | 113 | //Extracting the data 114 | char temp[200] = {}; 115 | 116 | int i = 0; 117 | 118 | for(; data[i] != '"'; i++) 119 | { 120 | temp[i] = data[i]; 121 | } 122 | 123 | 124 | //Checking if filename is given or not 125 | char* fileN = strchr (data + i, ' ') ; 126 | 127 | if (fileN != NULL) 128 | { 129 | fileN++; 130 | 131 | // create a FILE typed pointer 132 | FILE *file_pointer; 133 | 134 | // open the file for writing 135 | file_pointer = fopen (fileN, "w"); 136 | 137 | if (file_pointer != NULL) 138 | { 139 | // Write to the file 140 | fprintf (file_pointer,"%s", temp); 141 | 142 | // Close the file 143 | fclose (file_pointer); 144 | 145 | cout << "\n\nThe file has been successfully created."; 146 | } 147 | 148 | else 149 | cout << "\n\nCould not create the file."; 150 | } 151 | 152 | //If filename isn't given then simply print the data on console 153 | else 154 | { 155 | cout << endl << endl << temp; 156 | } 157 | } 158 | 159 | else 160 | cout << "\n\nInvalid command. Data not given"; 161 | } 162 | 163 | //UNZIP 164 | else if (strstr (buffer,"unzip") != NULL) 165 | { 166 | char* t = strchr (buffer,' '); 167 | 168 | if(t != NULL) 169 | { 170 | char temp[50] = "tar xvf"; 171 | 172 | if( system( strcat(temp,t) ) != 0 ) 173 | cout << "\n\nError unzipping the file."; 174 | else 175 | cout << "\n\nThe file has been successfully unzipped."; 176 | } 177 | 178 | else 179 | cout << "\n\nInvalid command. FileName not entered."; 180 | } 181 | 182 | 183 | //ZIP 184 | else if (strstr (buffer,"zip") != NULL) 185 | { 186 | char* t = strchr (buffer,' '); 187 | 188 | if(t != NULL) 189 | { 190 | char temp[50] = "tar cvf"; 191 | 192 | if( system( strcat( temp,t) ) != 0 ) 193 | cout << "\n\nError zipping the file."; 194 | else 195 | cout << "\n\nThe file has been successfully zipped."; 196 | } 197 | 198 | else 199 | cout << "\n\nInvalid command."; 200 | } 201 | 202 | 203 | else if (strstr (buffer,"out") != NULL) 204 | { 205 | int i = 1; 206 | 207 | //Checking '-l' 208 | bool lineByLine = false; 209 | char* lpos = strstr (buffer,"-l"); 210 | 211 | if (lpos != NULL) 212 | { 213 | lineByLine = true; 214 | i++; 215 | } 216 | 217 | string s(buffer); 218 | string fileN = ""; 219 | 220 | string delimiter = " "; 221 | size_t pos = 0; 222 | 223 | while ( i > 0 ) 224 | { 225 | pos = s.find(delimiter); 226 | s.erase(0, pos + delimiter.length()); 227 | i--; 228 | } 229 | 230 | 231 | //Now extracting the file names 232 | string f[3] = " "; 233 | 234 | i = 0; 235 | 236 | while ( (pos = s.find(delimiter)) != -1) 237 | { 238 | f[i] = s.substr(0, pos); 239 | s.erase(0, pos + delimiter.length()); 240 | i++; 241 | } 242 | 243 | //if atleast one filename is present 244 | 245 | if ( s != "out" && s != "-l" && s != "" ) 246 | { 247 | f[i] = s; 248 | 249 | //Opening the files and printing the contents 250 | 251 | int c; 252 | FILE *file; 253 | 254 | int j = 0; 255 | 256 | bool delay = false; 257 | char x; 258 | 259 | while ( j <= i) 260 | { 261 | char fName[50]; 262 | strcpy(fName, f[j].c_str()); 263 | 264 | //Printing the contents of the file(s) 265 | 266 | file = fopen(fName, "r"); 267 | char line[256]; 268 | 269 | cout << "\n\nThe contents of the file " << fName << " are as follows : \n\n"; 270 | 271 | if (file) 272 | { 273 | if (lineByLine) 274 | { 275 | while (fgets(line, sizeof(line), file)) 276 | { 277 | printf("%s", line); 278 | 279 | //Delay loop 280 | delay = true; 281 | 282 | while(delay) 283 | { 284 | cout << "\n\nPress some key to print the next line\n\n"; 285 | getchar(); 286 | delay = false; 287 | } 288 | } 289 | 290 | } 291 | 292 | else 293 | { 294 | while ((c = getc(file)) != EOF) 295 | putchar(c); 296 | } 297 | 298 | 299 | fclose(file); 300 | } 301 | 302 | else 303 | cout << "\n\nCould not open the file " << fName << " ."; 304 | 305 | j++; 306 | 307 | //Delay loop 308 | delay = true; 309 | 310 | while(delay) 311 | { 312 | cout << "\n\nPress some key to continue\n\n"; 313 | getchar(); 314 | delay = false; 315 | } 316 | } 317 | } 318 | 319 | else 320 | cout << "\n\nNo filename entered.\n\n"; 321 | } 322 | 323 | else 324 | cout << "\n\nInvalid Command. Kindly enter a valid command."; 325 | 326 | 327 | cin.ignore(); 328 | } 329 | 330 | 331 | 332 | cout << "\n\n\nExiting the CLI.\n\n"; 333 | 334 | return 0; 335 | } 336 | -------------------------------------------------------------------------------- /Code/cli.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harismuneer/Command-Line-Interpreter-CLI/6033bb8af7a4249722546aac7dc476bb9214d341/Code/cli.out -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 harismuneer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🔲 Command Line Interpreter - CLI 2 | 3 | views 4 | [![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](#) 5 | [![GitHub Forks](https://img.shields.io/github/forks/harismuneer/Command-Line-Interpreter-CLI.svg?style=social&label=Fork&maxAge=2592000)](https://www.github.com/harismuneer/Command-Line-Interpreter-CLI/fork) 6 | [![GitHub Issues](https://img.shields.io/github/issues/harismuneer/Command-Line-Interpreter-CLI.svg?style=flat&label=Issues&maxAge=2592000)](https://www.github.com/harismuneer/Command-Line-Interpreter-CLI/issues) 7 | [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat&label=Contributions&colorA=red&colorB=black )](#) 8 | 9 | 10 | A Command Line Interpreter made in C++ which supports commands like quit, remove, rename, rmdir, echo, out, zip, unzip. 11 | 12 | ## Problem Statement 13 | 14 | Making our own Command Line Interpreter 15 | In this problem you have to develop a small-scale command line interpreter. Your CLI should support the following commands: 16 | 17 | 1. **quit**: Exit your CLI 18 | 19 | 2. **remove file_name**: removes the given file name. (Hint: Use remove C/C++’s built-in function remove() ). 20 | 21 | 3. **rename old_name new_name**: rename the given file/folder. (Hint: Use C/C++’s built-in function rename() ). 22 | 23 | 4. **rmdir directory_name**: remove directory. Assume that the directory is always empty. You do not have to handle the deletion of a directory that is not empty. 24 | 25 | 5. **echo “data” optional_file_name**: Whatever data is given in the quotation marks is written to the given file. If the file name is not given, the data in string is simply printed on the screen. 26 | 27 | 6. **out -l file_name_1 file_name2 file_name_3**: The contents of given files are printed one by one on the screen. When the contents of one file are printed, user is asked to press some key to continue. User must enter at least 1 file name. (If the user has specified -l, then the file contents are printed line by line, and the user is asked to press some key to continue after each line.) 28 | 29 | 7. **zip destination file_name**: zips the given file/folder. (Hint: Use system() function. system(“tar cvf “+ destination+” “+ file_name) ). 30 | 31 | 8. **unzip file_name**: unzips the given zipped file. Use system() in this case, too. 32 | 33 | You can only use system() in zip/unzip command. You must not use it for any other command. 34 | 35 | ## How to Run 36 | 37 | Download the Code folder and using Ubuntu Bash or Windows or Linux Terminal, change current working directory to the Code folder. 38 | Then on the terminal, type 39 | 40 | ``` 41 | ./cli.out 42 | ``` 43 | 44 | 45 |
46 | 47 | 48 | ## Author 49 | You can get in touch with me on my LinkedIn Profile: [![LinkedIn Link](https://img.shields.io/badge/Connect-harismuneer-blue.svg?logo=linkedin&longCache=true&style=social&label=Follow)](https://www.linkedin.com/in/harismuneer) 50 | 51 | You can also follow my GitHub Profile to stay updated about my latest projects: [![GitHub Follow](https://img.shields.io/badge/Connect-harismuneer-blue.svg?logo=Github&longCache=true&style=social&label=Follow)](https://github.com/harismuneer) 52 | 53 | If you liked the repo then kindly support it by giving it a star ⭐ and share in your circles so more people can benefit from the effort. 54 | 55 | ## Contributions Welcome 56 | [![GitHub Issues](https://img.shields.io/github/issues/harismuneer/Command-Line-Interpreter-CLI.svg?style=flat&label=Issues&maxAge=2592000)](https://www.github.com/harismuneer/Command-Line-Interpreter-CLI/issues) 57 | 58 | If you find any bugs, have suggestions, or face issues: 59 | 60 | - Open an Issue in the Issues Tab to discuss them. 61 | - Submit a Pull Request to propose fixes or improvements. 62 | - Review Pull Requests from other contributors to help maintain the project's quality and progress. 63 | 64 | This project thrives on community collaboration! Members are encouraged to take the initiative, support one another, and actively engage in all aspects of the project. Whether it’s debugging, fixing issues, or brainstorming new ideas, your contributions are what keep this project moving forward. 65 | 66 | With modern AI tools like ChatGPT, solving challenges and contributing effectively is easier than ever. Let’s work together to make this project the best it can be! 🚀 67 | 68 | ## License 69 | [![MIT](https://img.shields.io/cocoapods/l/AFNetworking.svg?style=style&label=License&maxAge=2592000)](../master/LICENSE) 70 | 71 | Copyright (c) 2018-present, harismuneer 72 | 73 | 74 | 75 |
76 | 77 |

Waving hand 78 | Hey there, I'm Haris Muneer 👨🏻‍💻 79 |

80 | 81 | 82 | Total Github Stars 83 | Total Github Followers 84 | 85 |
86 | 87 | - 🛠️ Product Builder: Agile Product Manager with 5+ years of hands-on experience delivering SaaS solutions across sales, recruiting, AI, social media, and public sector domains. Background in Computer Science, with a proven track record of scaling products from inception to $XXM+ ARR, launching 3 top-ranking tools on Product Hunt, and developing solutions adopted by 250+ B2B clients in 40+ countries. 88 | 89 | - 🌟 Open Source Advocate: Passionate about making technology accessible, I’ve developed and open-sourced several software projects for web, mobile, desktop, and AI on my GitHub profile. These projects have been used by thousands of learners worldwide to enhance their skills and knowledge. 90 | 91 | - 📫 How to Reach Me: To learn more about my skills and work, visit my LinkedIn profile. For collaboration or inquiries, feel free to reach out via email. 92 | 93 |
94 | 95 |

🤝 Follow my journey

96 |

97 | 98 | 99 | 100 | 101 |

102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | --------------------------------------------------------------------------------