File tree Expand file tree Collapse file tree 4 files changed +36
-0
lines changed Expand file tree Collapse file tree 4 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,9 @@ Here is a short introduction how to use **booktrack-cli**.
40
40
41
41
# Delete a book from the given library by the book id
42
42
./booktrack-cli -l ~ /my_lib.json delete --by-id 2
43
+
44
+ # Edit the book from the given library with the book id 4
45
+ ./booktrack-cli -l ~ /my_lib.json edit --by-id 4
43
46
```
44
47
45
48
You can see a full list of commandline options below.
@@ -59,6 +62,7 @@ Subcommands:
59
62
list List books in the library
60
63
statistics Show statistics for loaded library
61
64
details Show details for a book
65
+ edit Edit a book in the library
62
66
```
63
67
64
68
## Notes
Original file line number Diff line number Diff line change @@ -91,6 +91,14 @@ void AddDetailsOptions(CLI::App& app, CliOptions& opt) {
91
91
sub_details->add_option (" --by-id" , opt.details .id , " " )->mandatory ();
92
92
}
93
93
94
+ void AddEditOptions (CLI::App& app, CliOptions& opt) {
95
+ auto sub_edit =
96
+ app.add_subcommand (" edit" , " Edit a book in the library" )
97
+ ->callback ([&opt]() { opt.command = PrimaryCommand::kEdit ; });
98
+
99
+ sub_edit->add_option (" --by-id" , opt.edit .id , " " )->mandatory ();
100
+ }
101
+
94
102
} // namespace
95
103
96
104
void booktrack_cli::AddCliOptions (CLI::App& app, CliOptions& opt) {
@@ -100,4 +108,5 @@ void booktrack_cli::AddCliOptions(CLI::App& app, CliOptions& opt) {
100
108
AddListOptions (app, opt);
101
109
AddStatisticsOptions (app, opt);
102
110
AddDetailsOptions (app, opt);
111
+ AddEditOptions (app, opt);
103
112
}
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ enum class PrimaryCommand {
16
16
kDelete ,
17
17
kStatistics ,
18
18
kDetails ,
19
+ kEdit ,
19
20
};
20
21
21
22
/* *
@@ -59,6 +60,13 @@ struct CliOptionsDetails {
59
60
size_t id{0 };
60
61
};
61
62
63
+ /* *
64
+ * @brief Contains available options for the "edit" subcommand
65
+ */
66
+ struct CliOptionsEdit {
67
+ size_t id{0 };
68
+ };
69
+
62
70
/* *
63
71
* @brief Structure containing all options for the command line interface
64
72
*/
@@ -70,6 +78,7 @@ struct CliOptions {
70
78
CliOptionsList list;
71
79
CliOptionsStatistics statistics;
72
80
CliOptionsDetails details;
81
+ CliOptionsEdit edit;
73
82
};
74
83
75
84
/* *
Original file line number Diff line number Diff line change @@ -93,6 +93,17 @@ void SubcmdDetails(Library& lib, const CliOptionsDetails& options) {
93
93
}
94
94
}
95
95
96
+ void SubcmdEdit (Library& lib, [[maybe_unused]] const CliOptionsEdit& options) {
97
+ // TODO: implement book editing
98
+ auto check_exist = lib.GetBookById (options.id );
99
+ if (check_exist.has_value ()) {
100
+ auto book = check_exist.value ();
101
+ std::cout << " Edit " << book.GetTitle () << ' \n ' ;
102
+ } else {
103
+ std::cout << " Could not find a book with id: " << options.id << " .\n " ;
104
+ }
105
+ }
106
+
96
107
} // namespace
97
108
98
109
int main (int argc, char * argv[]) {
@@ -120,6 +131,9 @@ int main(int argc, char* argv[]) {
120
131
case PrimaryCommand::kDetails :
121
132
SubcmdDetails (library_from_file, options.details );
122
133
break ;
134
+ case PrimaryCommand::kEdit :
135
+ SubcmdEdit (library_from_file, options.edit );
136
+ break ;
123
137
default :
124
138
break ;
125
139
}
You can’t perform that action at this time.
0 commit comments