Skip to content

Commit 0c5b27a

Browse files
committed
ref: Migrate to single 'notes' mode: remove category logic, simplify CLI, and implement copy_file
1 parent 5d887a3 commit 0c5b27a

11 files changed

Lines changed: 100 additions & 151 deletions

File tree

data/logs/history.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@
3737
[2025-06-17 06:51:50] UPDATE: notes/todo.txt
3838
[2025-06-17 06:52:01] READ: notes/todo.txt
3939
[2025-06-17 06:52:20] DELETE: notes/todo.txt
40+
[2025-07-27 17:42:21] CLEAN-DOCS: All documents cleared (notes, recipes, versions)
41+
[2025-07-27 17:53:00] DELETE: file.txt
42+
[2025-07-27 17:53:08] CREATE: file.txt
43+
[2025-07-27 17:53:23] UPDATE: file.txt

data/notes/file.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
hello
2+
3+
---------------------
4+
5+
new content

data/versions/notes_20250617_065140_todo.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hello
2+
hello

include/cli.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ typedef enum {
1212
// Structure to hold parsed command arguments
1313
typedef struct {
1414
command_type_t cmd_type;
15-
char category[64];
1615
char filename[256];
1716
bool valid;
1817
} command_args_t;
1918

2019
// Function declarations
2120
void print_usage(void);
2221
command_args_t parse_arguments(int argc, char *argv[]);
23-
bool validate_category(const char *category);
2422
bool confirm_action(const char *message);

include/file_ops.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#include <stdbool.h>
22

33
// Function declarations for file operations
4-
bool create_document(const char *category, const char *filename);
5-
bool read_document(const char *category, const char *filename);
6-
bool update_document(const char *category, const char *filename);
7-
bool delete_document(const char *category, const char *filename);
4+
bool create_document(const char *filename);
5+
bool read_document(const char *filename);
6+
bool update_document(const char *filename);
7+
bool delete_document(const char *filename);
88

99
// Helper functions
1010
bool ensure_category_dir(const char *category);
11-
char *get_full_path(const char *category, const char *filename);
12-
bool file_exists(const char *path);
11+
bool ensure_notes_dir(void);
12+
char *get_full_path(const char *filename);
13+
bool file_exists(const char *path);
14+
bool copy_file(const char *src, const char *dest);

include/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ void trim_whitespace(char *str);
2424
char *get_timestamp_string(void);
2525
bool ensure_versions_dir(void);
2626
bool ensure_logs_dir(void);
27-
bool log_operation(operation_type_t op_type, const char *category, const char *filename);
27+
bool log_operation(operation_type_t op_type, const char *filename);
2828
const char *get_operation_name(operation_type_t op_type);

src/cli.c

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@
66
#include "../include/utils.h"
77

88
void print_usage(void) {
9-
printf("Usage: NotesCLI <command> <category> <filename>\n\n");
9+
printf("Usage: NotesCLI <command> <filename>\n\n");
1010
printf("Commands:\n");
11-
printf(" create <category> <filename> - Create a new document\n");
12-
printf(" read <category> <filename> - Read an existing document\n");
13-
printf(" update <category> <filename> - Update an existing document\n");
14-
printf(" delete <category> <filename> - Delete an existing document\n\n");
15-
printf("Categories: recipes, notes, logs\n");
11+
printf(" create <filename> - Create a new note\n");
12+
printf(" read <filename> - Read an existing note\n");
13+
printf(" update <filename> - Update an existing note\n");
14+
printf(" delete <filename> - Delete an existing note\n\n");
1615
}
1716

1817
command_args_t parse_arguments(int argc, char *argv[]) {
19-
command_args_t args = {CMD_UNKNOWN, "", "", false};
18+
command_args_t args = {CMD_UNKNOWN, "", false};
2019

21-
if (argc != 4) {
20+
if (argc != 3) {
2221
return args;
2322
}
2423

@@ -35,31 +34,17 @@ command_args_t parse_arguments(int argc, char *argv[]) {
3534
return args;
3635
}
3736

38-
// Validate category and filename
39-
if (!validate_category(argv[2]) || !is_valid_filename(argv[3])) {
37+
// Validate filename
38+
if (!is_valid_filename(argv[2])) {
4039
return args;
4140
}
4241

43-
strncpy(args.category, argv[2], sizeof(args.category) - 1);
44-
strncpy(args.filename, argv[3], sizeof(args.filename) - 1);
42+
strncpy(args.filename, argv[2], sizeof(args.filename) - 1);
4543
args.valid = true;
4644

4745
return args;
4846
}
4947

50-
bool validate_category(const char *category) {
51-
const char *valid_categories[] = {"recipes", "notes", "logs", NULL};
52-
53-
for (const char **cat = valid_categories; *cat != NULL; cat++) {
54-
if (strcmp(category, *cat) == 0) {
55-
return true;
56-
}
57-
}
58-
59-
log_error("Invalid category. Valid categories are: recipes, notes, logs");
60-
return false;
61-
}
62-
6348
bool confirm_action(const char *message) {
6449
char response[8];
6550
printf("%s", message);

0 commit comments

Comments
 (0)