C · 4504 bytes Raw Blame History
1 /* gitswitch-c: Safe git identity switching with SSH/GPG isolation
2 * Simplified Phase 1 implementation for foundation testing
3 */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <getopt.h>
9 #include <unistd.h>
10
11 #include "gitswitch.h"
12 #include "error.h"
13
14 static void print_usage(const char *prog_name);
15 static void print_version(void);
16
17 int main(int argc, char *argv[]) {
18 int opt;
19 bool show_help = false;
20 bool show_version = false;
21 bool verbose = false;
22
23 static struct option long_options[] = {
24 {"help", no_argument, 0, 'h'},
25 {"version", no_argument, 0, 'v'},
26 {"verbose", no_argument, 0, 'V'},
27 {0, 0, 0, 0}
28 };
29
30 /* Initialize error handling */
31 if (error_init(LOG_LEVEL_INFO, NULL) != 0) {
32 fprintf(stderr, "Failed to initialize error handling\n");
33 return EXIT_FAILURE;
34 }
35
36 /* Parse command line options */
37 while ((opt = getopt_long(argc, argv, "hvV", long_options, NULL)) != -1) {
38 switch (opt) {
39 case 'h':
40 show_help = true;
41 break;
42 case 'v':
43 show_version = true;
44 break;
45 case 'V':
46 verbose = true;
47 set_log_level(LOG_LEVEL_DEBUG);
48 break;
49 default:
50 print_usage(argv[0]);
51 error_cleanup();
52 return EXIT_FAILURE;
53 }
54 }
55
56 /* Handle special commands */
57 if (show_version) {
58 print_version();
59 error_cleanup();
60 return EXIT_SUCCESS;
61 }
62
63 if (show_help) {
64 print_usage(argv[0]);
65 error_cleanup();
66 return EXIT_SUCCESS;
67 }
68
69 /* Phase 1 demonstration */
70 printf("┌──────────────────────────────────────┐\n");
71 printf("│ gitswitch-c Phase 1 Foundation │\n");
72 printf("└──────────────────────────────────────┘\n\n");
73
74 printf("✓ Error handling system: initialized\n");
75 printf("✓ Build system: working\n");
76 printf("✓ Command line parsing: functional\n");
77
78 if (verbose) {
79 log_info("Verbose mode enabled");
80 log_debug("Debug logging active");
81 }
82
83 /* Test error handling */
84 printf("\nTesting error handling:\n");
85 set_error(ERR_SUCCESS, "This is a test success message");
86 const error_context_t *err = get_last_error();
87 if (err->code == ERR_SUCCESS) {
88 printf("✓ Error context system working\n");
89 }
90
91 printf("\nPhase 1 foundation is solid! ✨\n");
92 printf("Ready for Phase 2: Configuration management\n\n");
93
94 /* Cleanup */
95 error_cleanup();
96 return EXIT_SUCCESS;
97 }
98
99 static void print_usage(const char *prog_name) {
100 printf("Usage: %s [OPTIONS] [COMMAND] [ARGS]\n", prog_name);
101 printf("\nThis is a Phase 1 development build of gitswitch-c\n");
102 printf("Safe git identity switching with SSH/GPG isolation\n\n");
103 printf("Options:\n");
104 printf(" --help, -h Show this help message\n");
105 printf(" --version, -v Show version information\n");
106 printf(" --verbose, -V Enable verbose output\n\n");
107 printf("Phase 1 Status:\n");
108 printf(" ✓ Error handling system\n");
109 printf(" ✓ Build system\n");
110 printf(" ✓ Command line parsing\n");
111 printf(" • Configuration management (Phase 2)\n");
112 printf(" • Git operations (Phase 3)\n");
113 printf(" • SSH security framework (Phase 4)\n");
114 printf(" • GPG security framework (Phase 5)\n");
115 printf(" • Full CLI integration (Phase 6)\n");
116 }
117
118 static void print_version(void) {
119 printf("%s version %s (Phase 1 Development Build)\n", GITSWITCH_NAME, GITSWITCH_VERSION);
120 printf("Safe git identity switching with SSH/GPG isolation\n");
121 printf("Built with security and reliability in mind\n\n");
122 printf("Phase 1 Features:\n");
123 printf("• Comprehensive error handling and logging\n");
124 printf("• Security-focused utility functions\n");
125 printf("• Foundation for SSH/GPG isolation\n");
126 printf("• Robust build system with hardening\n\n");
127 printf("Upcoming Features:\n");
128 printf("• Isolated SSH agents per account\n");
129 printf("• Separate GPG environments\n");
130 printf("• Comprehensive validation\n");
131 printf("• Secure memory handling\n");
132 }