-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
114 lines (105 loc) · 2.88 KB
/
main.c
File metadata and controls
114 lines (105 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "notes.h"
#include "utils.h"
#include "dirutils.h"
void print_usage();
int check_args(int argc, int expected, const char *command);
int main(int argc, char *argv[])
{
if (argv[0] != NULL && argc == 1)
{
print_usage();
return -1;
}
if (init_home_path() != 0 || init_notes_directory() != 0)
{
fprintf(stderr, "Error: Failed to initialize paths or directories.\n");
return -1;
}
// Validações das funções
// Processa comandos
if (strcmp(argv[1], "new") == 0)
{
if (check_args(argc, 4, "new") == 0)
{
new (argv[2], argv[3]);
}
}
else if (strcmp(argv[1], "edit") == 0)
{
edit(argv[2], argv[3]);
}
else if (strcmp(argv[1], "remove") == 0)
{
if (check_args(argc, 4, "remove") == 0)
{
removeNote(argv[2], argv[3]);
}
}
else if (strcmp(argv[1], "rename") == 0)
{
if (check_args(argc, 5, "rename") == 0)
{
renameDir(argv[2], argv[3], argv[4]);
}
}
else if (strcmp(argv[1], "backlink") == 0)
{
if (check_args(argc, 3, "backlink") == 0)
{
backlink(argv[2]);
}
}
else if (strcmp(argv[1], "ls") == 0)
{
if (argc < 3)
{
printf("Error: 'ls' requires an option (--oneline or --full).\nUse [notes --help] to see more.\n");
}
else if (strcmp(argv[2], "--oneline") == 0)
{
searchInDir(notes_path, NULL, 0, 0); // Modo oneline
}
else if (strcmp(argv[2], "--full") == 0)
{
searchInDir(notes_path, NULL, 1, 0); // Modo full
}
else if (strcmp(argv[1], "--help") == 0)
{
print_usage();
}
else
{
printf("Error: Unknown option '%s' for 'ls'.\nUse [notes --help] to see more\n", argv[2]);
}
}
else
{
printf("Error: Unknown command '%s'.\nUse [notes --help] to see more.\n", argv[1]);
}
free(notes_path);
return 0;
}
void print_usage()
{
printf("Usage: Notes <command> [options]\n"
"Commands:\n"
" new <category> <name> Create a new note\n"
" edit <category> <name> Edit an existing note\n"
" remove <category> <name> Remove a note\n"
" rename <old> <new> <name> Rename a category or note\n"
" backlink <keyword> Search for a given keyword\n"
" ls --oneline List notes in simple format\n"
" ls --full List notes with details\n");
}
int check_args(int argc, int expected, const char *command)
{
if (argc > expected)
{
printf("ERROR: '%s' only holds %d arguments.\n", command, expected - 2);
return 0;
}
return 0;
}