-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitssh
More file actions
1173 lines (1014 loc) · 33.8 KB
/
gitssh
File metadata and controls
1173 lines (1014 loc) · 33.8 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
#================================================================#
# GITSSH v0.1.0 - Git SSH User Session Manager CLI
# Clean command dispatcher without backward compatibility
#================================================================#
set -e
# Version information
readonly GITSSH_VERSION="0.1.0"
readonly GITSSH_NAME="GitSSH"
#================================================================#
# SCRIPT LOCATION DETECTION
#================================================================#
if [ -n "${BASH_SOURCE:-}" ]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
else
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
fi
# Determine modules directory based on installation structure
MODULES_DIR=""
# Check if we're running from the symlink location
if [ -L "$0" ]; then
# Follow symlink to actual executable location
REAL_SCRIPT="$(readlink "$0")"
if [ "${REAL_SCRIPT#/}" = "$REAL_SCRIPT" ]; then
# Relative path, resolve it
REAL_SCRIPT="$(cd "$(dirname "$0")" && cd "$(dirname "$REAL_SCRIPT")" && pwd)/$(basename "$REAL_SCRIPT")"
fi
SCRIPT_DIR="$(dirname "$REAL_SCRIPT")"
fi
# Look for modules in the modules/ subdirectory
if [ -f "$SCRIPT_DIR/modules/gitssh-utils.sh" ]; then
MODULES_DIR="$SCRIPT_DIR/modules"
elif [ -f "$SCRIPT_DIR/gitssh-utils.sh" ]; then
# Fallback: modules in same directory as script
MODULES_DIR="$SCRIPT_DIR"
elif [ -f "$HOME/.local/bin/gitssh-libs/modules/gitssh-utils.sh" ]; then
# Standard user installation
MODULES_DIR="$HOME/.local/bin/gitssh-libs/modules"
elif [ -f "/usr/local/lib/gitssh/modules/gitssh-utils.sh" ]; then
# System-wide installation
MODULES_DIR="/usr/local/lib/gitssh/modules"
else
printf "Error: Cannot locate GitSSH modules\n" >&2
printf "Searched locations:\n" >&2
printf " - %s/modules/gitssh-utils.sh\n" "$SCRIPT_DIR" >&2
printf " - %s/gitssh-utils.sh\n" "$SCRIPT_DIR" >&2
printf " - %s/.local/bin/gitssh-libs/modules/gitssh-utils.sh\n" "$HOME" >&2
printf " - /usr/local/lib/gitssh/modules/gitssh-utils.sh\n" >&2
exit 1
fi
#================================================================#
# CONFIGURATION
#================================================================#
readonly GIT_SSH_CONFIG_FILE="${GIT_SSH_CONFIG_FILE:-$HOME/.gitssh-sessions.json}"
readonly GIT_SSH_USERS_FILE="${GIT_SSH_USERS_FILE:-$HOME/.gitssh-users.json}"
readonly GIT_SESSION_TEMP="/tmp/gitssh-session-$$"
export GIT_SSH_CONFIG_FILE GIT_SSH_USERS_FILE GIT_SESSION_TEMP SCRIPT_DIR
#================================================================#
# MODULE LOADING
#================================================================#
_load_modules() {
local modules="utils init users sessions remotes commands setup"
local loaded_count=0
local failed_modules=""
for module in $modules; do
module_file="$MODULES_DIR/gitssh-${module}.sh"
if [ -f "$module_file" ]; then
if . "$module_file" 2>/dev/null; then
loaded_count=$((loaded_count + 1))
else
failed_modules="$failed_modules gitssh-${module}.sh"
printf "Error: Failed to load module: gitssh-%s.sh\n" "$module" >&2
fi
else
failed_modules="$failed_modules gitssh-${module}.sh"
printf "Error: Required module not found: gitssh-%s.sh\n" "$module" >&2
printf "Expected location: %s\n" "$module_file" >&2
fi
done
if [ "$loaded_count" -lt 7 ]; then
printf "Error: Only %d of 7 required modules loaded\n" "$loaded_count" >&2
if [ -n "$failed_modules" ]; then
printf "Failed modules:%s\n" "$failed_modules" >&2
fi
printf "Modules directory: %s\n" "$MODULES_DIR" >&2
exit 1
fi
# Optional: Print success message for debugging
# printf "Successfully loaded %d GitSSH modules from: %s\n" "$loaded_count" "$MODULES_DIR" >&2
}
#================================================================#
# COMMAND HANDLERS
#================================================================#
_handle_user_commands() {
subcommand="$1"
shift
case "$subcommand" in
add)
user_add "$@"
;;
remove|rm|delete)
user_remove "$@"
;;
list|ls)
user_list "$@"
;;
status|show|info)
user_status "$@"
;;
switch)
if [ $# -eq 0 ]; then
printf "Error: Username required\n" >&2
printf "Usage: gitssh user switch <username>\n" >&2
printf " gitssh user switch -g <username>\n" >&2
user_list --simple | sed 's/^/ /'
return 1
fi
case "$1" in
-g|--global)
shift
if [ $# -eq 0 ]; then
printf "Error: Username required after %s flag\n" "$1" >&2
return 1
fi
user_switch -g "$@"
;;
*)
user_switch "$@"
;;
esac
;;
edit)
user_edit "$@"
;;
*)
printf "Error: Unknown user command '%s'\n" "$subcommand" >&2
_show_user_help
return 1
;;
esac
}
_handle_session_commands() {
subcommand="$1"
shift
case "$subcommand" in
set|config|configure)
session_set "$@"
;;
show|status|info)
session_show "$@"
;;
clear|reset)
session_clear "$@"
;;
forget|remove)
session_forget "$@"
;;
list|ls)
session_list "$@"
;;
cleanup|clean)
session_cleanup "$@"
;;
export)
session_export "$@"
;;
import)
session_import "$@"
;;
*)
printf "Error: Unknown session command '%s'\n" "$subcommand" >&2
_show_session_help
return 1
;;
esac
}
_handle_ssh_commands() {
subcommand="$1"
shift
case "$subcommand" in
status|info)
ssh_status "$@"
;;
doctor|diagnose)
ssh_doctor "$@"
;;
repair|fix)
ssh_repair "$@"
;;
test)
if [ $# -eq 0 ]; then
printf "Error: SSH host required\n" >&2
printf "Usage: gitssh ssh test <hostname>\n" >&2
return 1
fi
ssh_test "$@"
;;
backup)
ssh_backup "$@"
;;
restore)
ssh_restore "$@"
;;
learn|help)
ssh_learn "$@"
;;
*)
printf "Error: Unknown ssh command '%s'\n" "$subcommand" >&2
_show_ssh_help
return 1
;;
esac
}
_handle_remote_commands() {
subcommand="$1"
shift
case "$subcommand" in
convert|ssh)
remote_convert "$@"
;;
add)
if [ $# -lt 2 ]; then
printf "Error: Remote name and URL required\n" >&2
printf "Usage: gitssh remote add <name> <url>\n" >&2
return 1
fi
remote_add "$@"
;;
check|analyze)
remote_check "$@"
;;
list|ls)
remote_list "$@"
;;
recommendations|recommend)
remote_recommendations "$@"
;;
*)
printf "Error: Unknown remote command '%s'\n" "$subcommand" >&2
_show_remote_help
return 1
;;
esac
}
_handle_git_commands() {
subcommand="$1"
shift
case "$subcommand" in
clone)
git_clone "$@"
;;
status|st)
git_status "$@"
;;
info|analyze)
git_info "$@"
;;
commit|ci)
git_commit "$@"
;;
push)
git_push "$@"
;;
pull)
git_pull "$@"
;;
fetch)
git_fetch "$@"
;;
init)
git_init "$@"
;;
*)
printf "Error: Unknown git command '%s'\n" "$subcommand" >&2
_show_git_help
return 1
;;
esac
}
_handle_setup_commands() {
subcommand="$1"
shift
case "$subcommand" in
github)
setup_github "$@"
;;
gitlab)
setup_gitlab "$@"
;;
*)
printf "Error: Unknown setup target '%s'\n" "$subcommand" >&2
_show_setup_help
return 1
;;
esac
}
_handle_config_commands() {
subcommand="$1"
shift
case "$subcommand" in
show|info)
config_show "$@"
;;
reset)
config_reset "$@"
;;
backup)
config_backup "$@"
;;
restore)
if [ $# -eq 0 ]; then
printf "Error: Backup path required\n" >&2
printf "Usage: gitssh config restore <backup-path>\n" >&2
return 1
fi
config_restore "$@"
;;
migrate)
config_migrate "$@"
;;
*)
printf "Error: Unknown config command '%s'\n" "$subcommand" >&2
_show_config_help
return 1
;;
esac
}
#================================================================#
# INSTALLATION COMMAND HANDLERS
#================================================================#
_handle_install_commands() {
subcommand="$1"
shift
# Find the installer script
installer_script=""
# Check common locations for installer
if [ -f "$SCRIPT_DIR/install" ]; then
installer_script="$SCRIPT_DIR/install"
elif [ -f "$INSTALL_DIR/install" ]; then
installer_script="$INSTALL_DIR/install"
elif [ -f "$(dirname "$0")/install" ]; then
installer_script="$(dirname "$0")/install"
else
printf "Error: Installer script not found\n" >&2
printf "Looked in:\n" >&2
printf " - %s/install\n" "$SCRIPT_DIR" >&2
printf " - %s/install\n" "$INSTALL_DIR" >&2
printf " - %s/install\n" "$(dirname "$0")" >&2
return 1
fi
# Make sure installer is executable
if [ ! -x "$installer_script" ]; then
chmod +x "$installer_script" 2>/dev/null || {
printf "Error: Cannot execute installer script: %s\n" "$installer_script" >&2
return 1
}
fi
case "$subcommand" in
install|reinstall)
printf "Running GitSSH installer...\n"
exec "$installer_script" install "$@"
;;
uninstall|remove)
printf "Running GitSSH uninstaller...\n"
exec "$installer_script" uninstall "$@"
;;
update|upgrade)
printf "Running GitSSH updater...\n"
exec "$installer_script" update "$@"
;;
verify|test-install)
printf "Verifying GitSSH installation...\n"
exec "$installer_script" verify "$@"
;;
diagnose|doctor-install)
printf "Running installation diagnostics...\n"
exec "$installer_script" diagnose "$@"
;;
*)
printf "Error: Unknown install command '%s'\n" "$subcommand" >&2
_show_install_help
return 1
;;
esac
}
_show_install_help() {
cat << 'EOF'
INSTALLATION MANAGEMENT:
gitssh install install Reinstall GitSSH system
gitssh install uninstall Completely remove GitSSH
gitssh install update Update to latest version
gitssh install verify Verify installation integrity
gitssh install diagnose Run installation diagnostics
INSTALLATION SHORTCUTS (aliases):
gitssh reinstall Same as 'install install'
gitssh uninstall Same as 'install uninstall'
gitssh update Same as 'install update'
gitssh verify Same as 'install verify'
gitssh diagnose Same as 'install diagnose'
EXAMPLES:
gitssh verify # Check if installation is healthy
gitssh update # Update GitSSH installation
gitssh uninstall # Remove GitSSH completely
gitssh install verify # Alternative full syntax
EOF
}
#================================================================#
# HELP FUNCTIONS
#================================================================#
_show_main_help() {
cat << 'EOF'
╔═══════════════════════════════════════════════════════════════╗
║ ║
║ ██████╗ ███████╗███████╗██╗ ██╗ ║
║ ██╔════╝ ██╗ ██╗ ██╔════╝██╔════╝██║ ██║ ║
║ ██║ ███╗══╝████║███████╗███████╗███████║ ║
║ ██║ ██║██║ ██║ ╚════██║╚════██║██╔══██║ ║
║ ██████╔╝██║ ██║ ███████║███████║██║ ██║ ║
║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝v0.1.0-Oz ║
║ <-POSIX Compliant-> ║
║ ║
╚═══════════════════════════════════════════════════════════════╝
Manage Multiple SSH Git and GitHub Account Sessions With Ease!
USAGE:
gitssh <command> [subcommand] [options]
SETUP & INITIALIZATION:
init Initialize GitSSH configuration
onboard|setup-wizard Interactive first-time setup wizard
validate|check|doctor Validate gitssh system configuration
ENHANCED GIT OPERATIONS:
clone <url> Enhanced git clone with auto-setup
status|st Enhanced git status with user info
commit|ci [opts] Enhanced git commit with user verification
push [opts] Enhanced git push with verification
fetch [opts] Enhanced git fetch with SSH verification
pull [opts] Enhanced git pull with SSH verification
info Show detailed repository information and SSH connection
USER MANAGEMENT:
switch|sw <user> Switch to user locally
switch|sw -g <user> Switch to user globally
user|users See user accounts and ssh accounts status
user add [opts] Add new user account
user remove|rm|delete <user> Remove user account
user list List all configured users
user switch <user> Switch to user locally
user switch -g <user> Switch to user globally
user status Show current user status
SESSION MANAGEMENT:
session|sess Show current repository and user session information
session set Set user for current repository
session status [options]Show current repository and user session information
session show [options] Show current repository and user session information
session clear Clear session data
session forget|remove Remove persistent config for repo
session list List all session repositories
session export <path> Export session data to file
session import <path> Import session data from file
session cleanup Cleanup stale session data
SSH MANAGEMENT:
ssh status|info Show SSH configuration status
ssh doctor Diagnose SSH connection issues
ssh repair Fix common SSH problems
ssh test <host> Test SSH connection
ssh backup Backup SSH configuration
ssh restore <path> Restore SSH configuration from backup
ssh learn Guide to adding new SSH hosts
SETUP WIZARDS:
setup github Setup GitHub SSH authentication
setup gitlab Setup GitLab SSH authentication
REMOTE MANAGEMENT:
remote|remotes Show git repository remotes
remote convert Convert HTTPS remote to SSH
remote add <name> <url> Add remote with SSH conversion
remote check Check remote configuration
remote list List all remotes with details
remote recommendations Show remote configuration recommendations
CONFIGURATION:
config show Show current configuration
config reset Reset configuration to defaults
config backup Backup configuration files
config restore <path> Restore from backup
config migrate Migrate from old configuration format
INSTALLATION/UNINSTALLATION/UPDATE MANAGEMENT:
gitssh reinstall Reinstall GitSSH system
gitssh uninstall|remove Completely remove GitSSH
gitssh update|upgrade Update to latest version
gitssh verify|test-install Verify installation integrity
gitssh diagnose|doctor-install Run installation diagnostics
INFORMATION:
help [command] Show help (general or command-specific)
version Show version information
EXAMPLES:
gitssh onboard # First-time setup
gitssh user add # Add new user
gitssh user switch work # Switch to work identity
gitssh session set # Configure current repo
gitssh clone github.com/user/repo.git
gitssh remote convert # Convert HTTPS to SSH
gitssh ssh status # Check SSH setup
EOF
}
_show_user_help() {
cat << 'EOF'
USER MANAGEMENT:
gitssh user add [options]
Add new user account interactively
Options:
--name <name> Full display name
--email <email> Email address
--ssh-host <host> SSH hostname
gitssh user remove [username]
Remove user account with confirmation
gitssh user list [options]
List all configured users
Options:
--simple Simple list for scripting
gitssh user switch <username>
Switch to specified user locally
gitssh user switch -g <username>
Switch to specified user globally
gitssh user status
Show current Git user and SSH status
EXAMPLES:
gitssh user add
gitssh user add --name "John Doe" --email "[email protected]"
gitssh user list
gitssh user switch work
gitssh user remove old-account
EOF
}
_show_session_help() {
cat << 'EOF'
SESSION MANAGEMENT:
gitssh session
Show current repository session information
gitssh session set [options]
Set user for current repository
Options:
--user <username> Set specific user
gitssh session show [options], gitssh session status [options]
Show current session status
Options:
--verbose Show detailed information
gitssh session clear
Clear all session data (temporary mappings)
gitssh session forget
Remove persistent configuration for current repository
gitssh session list
List all repositories in current session
EXAMPLES:
gitssh session
gitssh session status
gitssh session status --verbose
gitssh session set
gitssh session set --user work
gitssh session show
gitssh session show --verbose
gitssh session clear
EOF
}
_show_ssh_help() {
cat << 'EOF'
SSH MANAGEMENT:
gitssh ssh status
Show comprehensive SSH configuration status
gitssh ssh doctor
Diagnose SSH connection issues and problems
gitssh ssh repair
Automatically fix common SSH problems
gitssh ssh test <hostname>
Test SSH connection to specific host
gitssh ssh backup
Create backup of SSH configuration
gitssh ssh restore <path>
Restore SSH configuration from backup
EXAMPLES:
gitssh ssh status
gitssh ssh doctor
gitssh ssh test github-work
gitssh ssh repair
EOF
}
_show_remote_help() {
cat << 'EOF'
REMOTE MANAGEMENT:
gitssh remote convert
Convert HTTPS remote to SSH for current repository
gitssh remote add <name> <url>
Add new remote with SSH conversion
gitssh remote check
Analyze current remote configuration
gitssh remote list
Show all remotes with detailed information
EXAMPLES:
gitssh remote convert
gitssh remote add upstream [email protected]:upstream/repo.git
gitssh remote check
gitssh remote list
EOF
}
_show_git_help() {
cat << 'EOF'
ENHANCED GIT OPERATIONS:
gitssh clone <url> [directory]
Enhanced git clone with automatic user setup
gitssh status
Enhanced git status with user and remote information
gitssh info
Show detailed repository information and analysis
gitssh commit [options]
Enhanced git commit with user verification
gitssh push [options]
Enhanced git push with SSH testing and verification
EXAMPLES:
gitssh clone [email protected]:user/repo.git
gitssh status
gitssh commit -m "Update feature"
gitssh push origin main
EOF
}
_show_setup_help() {
cat << 'EOF'
SETUP WIZARDS:
gitssh setup github
Interactive GitHub SSH key setup wizard
- Generates SSH keys
- Configures SSH hosts
- Guides through GitHub key addition
- Tests connectivity
gitssh setup gitlab
Interactive GitLab SSH key setup wizard
- Supports GitLab.com and self-hosted instances
- Complete SSH configuration
- Connection testing
EXAMPLES:
gitssh setup github
gitssh setup gitlab
EOF
}
_show_config_help() {
cat << 'EOF'
CONFIGURATION MANAGEMENT:
gitssh config show
Show current system configuration and status
gitssh config reset
Reset all configuration to defaults (destructive)
gitssh config backup
Create timestamped backup of all configuration
gitssh config restore <path>
Restore configuration from backup directory
gitssh config migrate
Migrate from old configuration format
EXAMPLES:
gitssh config show
gitssh config backup
gitssh config restore ~/gitssh-backup-20250101
EOF
}
_show_command_help() {
command="$1"
case "$command" in
user) _show_user_help ;;
session) _show_session_help ;;
ssh) _show_ssh_help ;;
remote) _show_remote_help ;;
git) _show_git_help ;;
setup) _show_setup_help ;;
config) _show_config_help ;;
*) _show_main_help ;;
esac
}
#================================================================#
# GLOBAL OPTIONS PARSING
#================================================================#
_parse_global_options() {
GITSSH_VERBOSE=false
GITSSH_QUIET=false
GITSSH_FORCE=false
while [ $# -gt 0 ]; do
case "$1" in
--verbose|-v)
GITSSH_VERBOSE=true
export GITSSH_VERBOSE
shift
;;
--quiet|-q)
GITSSH_QUIET=true
export GITSSH_QUIET
shift
;;
--force|-f)
GITSSH_FORCE=true
export GITSSH_FORCE
shift
;;
--help|-h)
_show_main_help
exit 0
;;
--version)
printf "%s v%s\n" "$GITSSH_NAME" "$GITSSH_VERSION"
exit 0
;;
--)
shift
break
;;
-*)
printf "Error: Unknown global option '%s'\n" "$1" >&2
printf "Use 'gitssh --help' for usage information\n" >&2
exit 1
;;
*)
break
;;
esac
done
}
#================================================================#
# MAIN COMMAND ROUTER
#================================================================#
_route_command() {
if [ $# -eq 0 ]; then
_show_main_help
return 0
fi
command="$1"
shift
# Handle help requests for any command
case "${1:-}" in
--help|-h|help)
_show_command_help "$command"
return 0
;;
esac
case "$command" in
# Setup and initialization
init|initialize)
system_init "$@"
;;
onboard|setup-wizard)
system_onboard "$@"
;;
validate|check|doctor)
system_validate "$@"
;;
setup)
if [ $# -eq 0 ]; then
printf "Error: Setup target required\n" >&2
_show_setup_help
return 1
fi
_handle_setup_commands "$@"
;;
# User management
user|users)
if [ $# -eq 0 ]; then
user_status
else
_handle_user_commands "$@"
fi
;;
# Session management
session|sess)
if [ $# -eq 0 ]; then
session_show
else
_handle_session_commands "$@"
fi
;;
# SSH management
ssh)
if [ $# -eq 0 ]; then
ssh_status
else
_handle_ssh_commands "$@"
fi
;;
# Remote management
remote|remotes)
if [ $# -eq 0 ]; then
remote_list
else
_handle_remote_commands "$@"
fi
;;
# Git operations (direct commands)
clone)
if [ $# -eq 0 ]; then
printf "Error: Repository URL required\n" >&2
printf "Usage: gitssh clone <url> [directory]\n" >&2
return 1
fi
git_clone "$@"
;;
status|st)
git_status "$@"
;;
info|analyze)
git_info "$@"
;;
commit|ci)
git_commit "$@"
;;
push)
git_push "$@"
;;
pull)
git_pull "$@"
;;
fetch)
git_fetch "$@"
;;
# Configuration management
config|configuration)
if [ $# -eq 0 ]; then
config_show
else
_handle_config_commands "$@"
fi
;;
# Global user switching (shortcut)
switch|sw)
if [ $# -eq 0 ]; then
printf "Error: Username required\n" >&2
printf "Usage: gitssh switch <username>\n" >&2
user_list_simple
return 1
fi
user_switch "$@"
;;
# Information
help|--help|-h)
if [ $# -gt 0 ]; then
_show_command_help "$1"
else
_show_main_help
fi
;;
version|--version|-v)
printf "%s v%s\n" "$GITSSH_NAME" "$GITSSH_VERSION"
;;
# Installation management
install)
if [ $# -eq 0 ]; then
printf "Error: Install command required\n" >&2
_show_install_help
return 1
fi
_handle_install_commands "$@"
;;
# Direct aliases for installation commands (without "install" prefix)
reinstall)
_handle_install_commands "install" "$@"
;;
uninstall|remove)
_handle_install_commands "uninstall" "$@"
;;
update|upgrade)
_handle_install_commands "update" "$@"
;;
verify|test-install)
_handle_install_commands "verify" "$@"
;;
diagnose|doctor-install)
_handle_install_commands "diagnose" "$@"