diff --git a/src/subcmds/add.c b/src/subcmds/add.c index 8595be7..07e9cb2 100644 --- a/src/subcmds/add.c +++ b/src/subcmds/add.c @@ -6,7 +6,12 @@ #include "../file_io.h" bool add_cmd(Cli *cli) { + // Initialize structures and validate inputs struct Add a = cli->cmd.add; + if (!a.command) { + printf("Error invalid args: must provide command to alias.\n"); + return false; + } HashTable *ht; create_hash_table(&ht, INITIAL_CAPACITY, LOAD_FACTOR); Entry *entry; diff --git a/src/subcmds/remove.c b/src/subcmds/remove.c index d234f8f..9eaa1b5 100644 --- a/src/subcmds/remove.c +++ b/src/subcmds/remove.c @@ -6,19 +6,22 @@ #include bool remove_cmd(Cli *cli) { - // Initialize structures and variables + // Initialize structures and validate inputs struct Remove r = cli->cmd.remove; + if (!r.aliases) { + printf("No %s provided.\n", r.recursive ? "section" : "alias"); + } HashTable *ht; create_hash_table(&ht, INITIAL_CAPACITY, LOAD_FACTOR); Entry *entry; + // Pick the alias file name ('.env' if 'a.local', else '~/.aliases') const char *alias_fname = (r.local) ? AUTOENV_FNAME : ALIAS_FNAME; // Make sure the alias file exists if (access(alias_fname, F_OK) == -1) { FILE *f = fopen(alias_fname, "w"); fclose(f); } - // Open the correct alias file ('.env' if 'a.local', else '~/.aliases') FILE *alias_f = fopen(alias_fname, "r"); if (!alias_f) return cleanup("Error: aliases file not found: %s\n", alias_fname, ht, 0, 0); @@ -70,6 +73,5 @@ bool remove_cmd(Cli *cli) { perror("Error renaming file.\n"); return false; } - // Cleanup cli return true; }