@@ -52,20 +52,17 @@ bool print_part(Callable&& fmt_or_adaparse_print, std::string_view get_part,
5252 if (get_part == " protocol" ) {
5353 fmt_or_adaparse_print (" {}\n " , url.get_protocol ());
5454 return true ;
55- }
56- if (get_part == " password" ) {
55+ } else if (get_part == " password" ) {
5756 fmt_or_adaparse_print (" {}\n " , url.get_password ());
5857 return true ;
59- }
60- if (get_part == " pathname" ) {
58+ } else if (get_part == " pathname" ) {
6159 fmt_or_adaparse_print (" {}\n " , url.get_pathname ());
6260 return true ;
6361 }
62+ } else if (get_part == " hostname" ) {
63+ fmt_or_adaparse_print (" {}\n " , url.get_hostname ());
64+ return true ;
6465 }
65- } else if (get_part == " hostname" ) {
66- fmt_or_adaparse_print (" {}\n " , url.get_hostname ());
67- return true ;
68-
6966 } else if (get_part == " username" ) {
7067 fmt_or_adaparse_print (" {}\n " , url.get_username ());
7168 return true ;
@@ -88,12 +85,12 @@ int piped_file(Callable&& adaparse_print, const cxxopts::ParseResult result,
8885
8986 uint64_t before = nano ();
9087
91- size_t total_bytes_read = 0 ;
92- size_t bytes_read_this_loop_iteration;
93- size_t offset = 0 ;
94- size_t lines = 0 ;
95- size_t blocks = 0 ;
96- std::string get_part;
88+ size_t total_bytes_read{ 0 } ;
89+ size_t bytes_read_this_loop_iteration{ 0 } ;
90+ size_t offset{ 0 } ;
91+ size_t lines{ 0 } ;
92+ size_t blocks{ 0 } ;
93+ std::string get_part{} ;
9794 if (result.count (" get" )) {
9895 get_part = result[" get" ].as <std::string>();
9996 }
@@ -121,7 +118,7 @@ int piped_file(Callable&& adaparse_print, const cxxopts::ParseResult result,
121118 while (li.find_another_complete_line ()) {
122119 std::string_view line = li.grab_line ();
123120
124- ada::result<ada::url_aggregator> url = ada::parse (line);
121+ auto url = ada::parse<ada::url_aggregator> (line);
125122 if (!url) {
126123 adaparse_print (" Invalid URL: {}\n " , line);
127124 } else if (!get_part.empty ()) {
@@ -138,7 +135,7 @@ int piped_file(Callable&& adaparse_print, const cxxopts::ParseResult result,
138135 // have a line of length offset at cachebuffer.get()
139136 std::string_view line (cachebuffer.get (), offset);
140137
141- ada::result<ada::url_aggregator> url = ada::parse (line);
138+ auto url = ada::parse<ada::url_aggregator> (line);
142139 if (!url) {
143140 adaparse_print (" Invalid URL:{}\n " , line);
144141 } else if (!get_part.empty ()) {
@@ -207,30 +204,22 @@ int main(int argc, char** argv) {
207204 cxxopts::Options options (" adaparse" ,
208205 " Command-line version of the Ada URL parser" );
209206
210- options.add_options ()(" d,diagram" , " Print a diagram of the result" ,
211- cxxopts::value<bool >()->default_value (" false" ))(
212- " u,url" , " URL Parameter (required)" , cxxopts::value<std::string>())(
213- " h,help" , " Print usage" )(
214- " g,get" , " Get a specific part of the URL (e.g., 'origin', 'host', etc.)" ,
215- cxxopts::value<std::string>())(
216- " b,benchmark" , " Display chronometer for piped_file function" ,
217- cxxopts::value<bool >()->default_value (" false" ))(
218- " p,path" , " Takes in a path to a file and process all the URL within" ,
219- cxxopts::value<std::string>())(
220- " o,output" , " Takes in a path and outputs to a text file." ,
221- cxxopts::value<std::string>()->default_value (" __no_output__" ))
222-
223- ;
207+ // clang-format off
208+ options.add_options ()
209+ (" d,diagram" , " Print a diagram of the result" , cxxopts::value<bool >()->default_value (" false" ))
210+ (" u,url" , " URL" , cxxopts::value<std::string>())
211+ (" g,get" , " Get a specific part of the URL (e.g., 'origin', 'host', etc.)" , cxxopts::value<std::string>())
212+ (" b,benchmark" , " Display chronometer for piped_file function" , cxxopts::value<bool >()->default_value (" false" ))
213+ (" p,path" , " Takes in a path to a file and process all the URL within" , cxxopts::value<std::string>())
214+ (" o,output" , " Takes in a path and outputs to a text file." , cxxopts::value<std::string>()->default_value (" /dev/null" ))
215+ (" h,help" , " Print usage" );
216+ // clang-format on
217+
224218 options.parse_positional ({" url" });
225219
226220 auto result = options.parse (argc, argv);
227221
228222 std::string output_filename = result[" output" ].as <std::string>();
229-
230- result[" output" ].as <std::string>() == " __no_output__"
231- ? output_filename = " /dev/null"
232- : output_filename = result[" output" ].as <std::string>();
233-
234223 auto out = fmt::output_file (output_filename);
235224 bool has_result = result.count (" output" );
236225
@@ -255,15 +244,14 @@ int main(int argc, char** argv) {
255244 }
256245
257246 if (result.count (" path" )) {
258- std::string filepath = result[" path" ].as <std::string>();
259- FILE* file = fopen (filepath .c_str (), " r" );
247+ auto file_path = result[" path" ].as <std::string>();
248+ auto file = fopen (file_path .c_str (), " r" );
260249 if (file) {
261250 piped_file (adaparse_print, result, file);
262251 fclose (file);
263252 return EXIT_SUCCESS;
264253 } else {
265- int err = errno;
266- fmt::print (stderr, " Error opening file: {}\n " , strerror (err));
254+ fmt::print (stderr, " Error opening file: {}\n " , strerror (errno));
267255 return EXIT_FAILURE;
268256 }
269257 }
@@ -274,14 +262,15 @@ int main(int argc, char** argv) {
274262 return EXIT_SUCCESS;
275263 }
276264
277- std::string url_string = result[" url" ].as <std::string>();
265+ auto input_url = result[" url" ].as <std::string>();
278266 bool to_diagram = result[" diagram" ].as <bool >();
279267
280- ada::result<ada::url_aggregator> url = ada::parse (url_string );
268+ auto url = ada::parse<ada::url_aggregator>(input_url );
281269 if (!url) {
282- fmt::print (stderr, " Invalid URL: {}\n " , url_string );
270+ fmt::print (stderr, " Invalid URL: {}\n " , input_url );
283271 return EXIT_FAILURE;
284272 }
273+
285274 if (result.count (" get" )) {
286275 std::string get_part = result[" get" ].as <std::string>();
287276
@@ -292,6 +281,7 @@ int main(int argc, char** argv) {
292281 return print_part (print_lambda, get_part, url.value ()) ? EXIT_SUCCESS
293282 : EXIT_FAILURE;
294283 };
284+
295285 if (to_diagram) {
296286 fmt::print (" {}\n " , url->to_diagram ());
297287 } else {
0 commit comments