2025-08-17 17:48:24 +01:00
|
|
|
// Copyright 2025.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
2025-08-14 11:51:07 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2025-08-17 15:36:32 +01:00
|
|
|
"os"
|
2025-08-19 09:42:09 +01:00
|
|
|
"path/filepath"
|
2025-08-17 15:36:32 +01:00
|
|
|
"time"
|
|
|
|
|
|
2025-08-19 09:42:09 +01:00
|
|
|
"github.com/Adembc/lazyssh/internal/adapters/data/file"
|
|
|
|
|
"github.com/Adembc/lazyssh/internal/logger"
|
|
|
|
|
|
2025-08-17 11:09:20 +01:00
|
|
|
"github.com/Adembc/lazyssh/internal/adapters/ui"
|
|
|
|
|
"github.com/Adembc/lazyssh/internal/core/services"
|
2025-08-14 11:51:07 +01:00
|
|
|
"github.com/spf13/cobra"
|
2025-08-17 15:36:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
version = "develop"
|
|
|
|
|
gitCommit = "unknown"
|
|
|
|
|
buildTime = time.Now().Format("2006-01-02 15:04:05")
|
2025-08-14 11:51:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
2025-08-19 09:42:09 +01:00
|
|
|
log, err := logger.New("LAZYSSH")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
defer log.Sync()
|
|
|
|
|
|
|
|
|
|
home, err := os.UserHomeDir()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorw("failed to get user home directory", "error", err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
sshConfigFile := filepath.Join(home, ".ssh", "config")
|
|
|
|
|
metaDataFile := filepath.Join(home, ".lazyssh", "metadata.json")
|
|
|
|
|
|
|
|
|
|
serverRepo := file.NewServerRepo(log, sshConfigFile, metaDataFile)
|
|
|
|
|
// serverInMemoryRepo := memory.NewServerRepository(log)
|
|
|
|
|
serverService := services.NewServerService(log, serverRepo)
|
|
|
|
|
tui := ui.NewTUI(log, serverService, version, gitCommit, buildTime)
|
2025-08-14 11:51:07 +01:00
|
|
|
|
|
|
|
|
rootCmd := &cobra.Command{
|
2025-08-17 11:09:20 +01:00
|
|
|
Use: ui.AppName,
|
2025-08-14 11:51:07 +01:00
|
|
|
Short: "Lazy SSH server picker TUI",
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2025-08-17 11:09:20 +01:00
|
|
|
return tui.Run()
|
2025-08-14 11:51:07 +01:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
rootCmd.SilenceUsage = true
|
|
|
|
|
|
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
2025-08-17 15:36:32 +01:00
|
|
|
_, _ = fmt.Fprintln(os.Stderr, err)
|
2025-08-14 11:51:07 +01:00
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
}
|