Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
main.cpp File Reference

Entry point for the application. Parses command-line arguments and either starts the HTTP server or fetches and displays a GitHub user. More...

#include "config.hpp"
#include "server.hpp"
#include "user.hpp"
#include <iostream>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Main function that initializes and runs the application.
 

Detailed Description

Entry point for the application. Parses command-line arguments and either starts the HTTP server or fetches and displays a GitHub user.

This file contains the main function which acts as the orchestrator of the program. It interprets the configuration from the user, and based on that configuration, it either launches a local HTTP server or performs a GitHub API request to fetch user data, then displays it to stdout.

Definition in file main.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Main function that initializes and runs the application.

This function performs the following steps:

  • Parses command-line arguments into an AppConfig object.
  • Based on the parsed configuration:
    • If run_server is true, launches the HTTP server on the specified port.
    • Otherwise, fetches a GitHub user and prints the result.

Any exceptions thrown during the execution are caught and logged to stderr, with a non-zero return code indicating failure.

Parameters
argcArgument count.
argvArgument vector.
Returns
int Exit status code (0 for success, non-zero for failure).

Definition at line 35 of file main.cpp.

35 {
36 try {
37 // Convert argv to vector<string> for easier handling
38 std::vector<std::string> args(argv + 1, argv + argc);
39
40 // Parse arguments into configuration
41 AppConfig config = parse_arguments(args);
42
43 if (config.run_server) {
44 // Start HTTP server if --server option is set
45 start_http_server(config.port);
46 } else {
47 // Otherwise fetch and display GitHub user info
48 User user = User::fetch_github_user(config.username);
49 user.print();
50 }
51
52 return 0;
53 } catch (const std::exception &ex) {
54 std::cerr << "Error: " << ex.what() << "\n";
55 return 1;
56 }
57}
AppConfig parse_arguments(const std::vector< std::string > &args)
Parses command-line arguments into an AppConfig structure.
Definition config.cpp:31
void start_http_server(int port)
Starts an HTTP server on the specified port.
Definition server.c:59
Structure representing a GitHub user.
Definition user.h:9

References parse_arguments(), and start_http_server().