@@ -28,44 +28,52 @@ import (
2828)
2929
3030var (
31- version = "develop"
32- gitCommit = "unknown"
33- )
31+ version = "develop"
32+ gitCommit = "unknown"
33+ sshConfigFile string
3434
35- func main () {
36- log , err := logger .New ("LAZYSSH" )
37- if err != nil {
38- fmt .Println (err )
39- os .Exit (1 )
40- }
35+ rootCmd = & cobra.Command {
36+ Use : ui .AppName ,
37+ Short : "Lazy SSH server picker TUI" ,
38+ RunE : func (cmd * cobra.Command , args []string ) error {
39+ log , err := logger .New ("LAZYSSH" )
40+ if err != nil {
41+ fmt .Println (err )
42+ os .Exit (1 )
43+ }
4144
42- //nolint:errcheck // log.Sync may return an error which is safe to ignore here
43- defer log .Sync ()
45+ //nolint:errcheck // log.Sync may return an error which is safe to ignore here
46+ defer log .Sync ()
4447
45- home , err := os .UserHomeDir ()
46- if err != nil {
47- log .Errorw ("failed to get user home directory" , "error" , err )
48- //nolint:gocritic // exitAfterDefer: ensure immediate exit on unrecoverable error
49- os .Exit (1 )
50- }
51- sshConfigFile := filepath .Join (home , ".ssh" , "config" )
52- metaDataFile := filepath .Join (home , ".lazyssh" , "metadata.json" )
48+ home , err := os .UserHomeDir ()
49+ if err != nil {
50+ log .Errorw ("failed to get user home directory" , "error" , err )
51+ // nolint:gocritic // exitAfterDefer: ensure immediate exit on unrecoverable error
52+ os .Exit (1 )
53+ }
5354
54- serverRepo := ssh_config_file .NewRepository (log , sshConfigFile , metaDataFile )
55- serverService := services .NewServerService (log , serverRepo )
56- tui := ui .NewTUI (log , serverService , version , gitCommit )
55+ if sshConfigFile == "" {
56+ sshConfigFile = filepath .Join (home , ".ssh" , "config" )
57+ }
58+ metaDataFile := filepath .Join (home , ".lazyssh" , "metadata.json" )
59+ serverRepo := ssh_config_file .NewRepository (log , sshConfigFile , metaDataFile )
60+ serverService := services .NewServerService (log , serverRepo )
61+ tui := ui .NewTUI (log , serverService , version , gitCommit )
5762
58- rootCmd := & cobra.Command {
59- Use : ui .AppName ,
60- Short : "Lazy SSH server picker TUI" ,
61- RunE : func (cmd * cobra.Command , args []string ) error {
6263 return tui .Run ()
6364 },
6465 }
65- rootCmd . SilenceUsage = true
66+ )
6667
68+ func main () {
6769 if err := rootCmd .Execute (); err != nil {
6870 _ , _ = fmt .Fprintln (os .Stderr , err )
6971 os .Exit (1 )
7072 }
7173}
74+
75+ func init () {
76+ rootCmd .PersistentFlags ().StringVar (& sshConfigFile , "sshconfig" , "" , "path to ssh config file (default: ~/.ssh/config)" )
77+
78+ rootCmd .SilenceUsage = true
79+ }
0 commit comments