added ls command for listing all scripts

This commit is contained in:
lucaspalomodevelop 2023-05-06 23:30:26 +02:00
parent c5ebf9637e
commit a90518816a
3 changed files with 20 additions and 4 deletions

View File

@ -1,5 +1,5 @@
CC = g++
CFLAGS = -std=c++11 -Wall
CFLAGS = -std=c++17 -Wall
SRCDIR = ./src
BINDIR = ./bin

View File

@ -21,6 +21,7 @@ void input(int argc, char *argv[])
command.addCommand("run", runScript);
command.addCommand("help", help);
command.addCommand("ls", listScripts);
command.addDefaultCommand(runScript);
command.runCommand(argv[1], argc, argv);
}
@ -36,6 +37,17 @@ void runScript(int argc, char *argv[])
system(script.c_str());
}
// list all scripts in the autom directory
void listScripts(int argc, char *argv[])
{
std::cout << "Scripts:" << std::endl;
for (const auto &entry : std::filesystem::directory_iterator(dir))
{
std::string name = entry.path().filename().string();
std::cout << " " << name << std::endl;
}
}
// help function for showing help message
void help(int argc, char *argv[])
{

View File

@ -2,6 +2,8 @@
#include <iostream>
#include <string>
#include <sys/stat.h>
#include <filesystem>
#include "inputparser.h"
#include "command.h"
@ -19,9 +21,11 @@ std::string dir = home + "/autom";
// input function for parsing arguments and creating commands and running them
void input(int argc, char *argv[]);
// run a script with is in the autom directory
void runScript(int argc,char *argv[]);
void runScript(int argc, char *argv[]);
// list all scripts in the autom directory
void listScripts(int argc, char *argv[]);
// help function for showing help message
void help(int argc,char *argv[]);
void help(int argc, char *argv[]);
// void create(int argc,char *argv[]);
// void remove(int argc,char *argv[]);
// void list(int argc,char *argv[]);