diff --git a/cmd/software/launch.go b/cmd/software/launch.go new file mode 100644 index 0000000..31c9287 --- /dev/null +++ b/cmd/software/launch.go @@ -0,0 +1,35 @@ +package software + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +var launchCmd = &cobra.Command{ + Use: "launch", + Short: "Launch a software package", + Run: func(cmd *cobra.Command, args []string) { + if len(args) == 0 { + fmt.Println("No software specified.") + os.Exit(1) + } + + sw, exists := softwareMap[args[0]] + if !exists { + fmt.Printf("Software '%s' not found.\n", args[0]) + os.Exit(1) + } + + if err := sw.Launch(); err != nil { + fmt.Printf("Failed to launch '%s': %v\n", args[0], err) + os.Exit(1) + } + }, +} + +func init() { + SoftwareCmd.AddCommand(launchCmd) + +} diff --git a/cmd/software/root.go b/cmd/software/root.go new file mode 100644 index 0000000..41e7016 --- /dev/null +++ b/cmd/software/root.go @@ -0,0 +1,57 @@ +package software + +import ( + "context" + "log" + + "github.com/Print-and-Panic/panic-cli/cmd" + "github.com/Print-and-Panic/panic-cli/internal/ai" + "github.com/Print-and-Panic/panic-cli/internal/config" + "github.com/Print-and-Panic/panic-cli/internal/github" + "github.com/Print-and-Panic/panic-cli/internal/software" + "github.com/spf13/cobra" + "google.golang.org/genai" +) + +var SoftwareCmd = &cobra.Command{ + Use: "software", + Short: "Software management", + PersistentPreRun: func(cmd *cobra.Command, args []string) { + initSoftwareMap() + }, +} + +var softwareMap map[string]software.Launchable + +func initSoftwareMap() { + + geminiConfig := &genai.GenerateContentConfig{ + SystemInstruction: genai.NewContentFromText(software.BambuReleaseSummarizer, genai.RoleUser), + } + geminiProvider, err := ai.NewGeminiProvider(context.Background(), config.AppConfig.AI.Gemini.APIKey, ai.GeminiModel2p5Flash, geminiConfig) + if err != nil { + log.Fatal(err) + } + + softwareList := []software.Launchable{ + &software.BambuStudio{ + AppImage: software.AppImage{ + Path: config.AppConfig.Software["bambu"].Path, + }, + GitHubProject: github.GitHubProject{ + Owner: "bambulab", + Repo: "BambuStudio", + }, + GeminiProvider: *geminiProvider, + }, + } + + softwareMap = make(map[string]software.Launchable) + for _, s := range softwareList { + softwareMap[s.ID()] = s + } +} + +func init() { + cmd.RootCmd.AddCommand(SoftwareCmd) +} diff --git a/cmd/software/update.go b/cmd/software/update.go new file mode 100644 index 0000000..a8ed0ab --- /dev/null +++ b/cmd/software/update.go @@ -0,0 +1,86 @@ +package software + +import ( + "bytes" + "context" + "fmt" + "os" + "strings" + + "github.com/Print-and-Panic/panic-cli/internal/software" + "github.com/spf13/cobra" +) + +var updateCmd = &cobra.Command{ + Use: "update", + Short: "Update a software package", + Run: func(cmd *cobra.Command, args []string) { + + if len(args) == 0 { + fmt.Println("No software specified.") + os.Exit(1) + } + + sw, exists := softwareMap[args[0]] + if !exists { + fmt.Printf("Software '%s' not found.\n", args[0]) + os.Exit(1) + } + + if updater, ok := sw.(software.Updateable); ok { + newestVersion, err := checkForUpdates(updater) + if err != nil { + fmt.Printf("Failed to check for updates: %v\n", err) + os.Exit(1) + } + if newestVersion != "" { + if summarizer, ok := sw.(software.Summarizer); ok { + notes, err := updater.GetReleaseNotes(newestVersion) + if err != nil { + fmt.Printf("Failed to get release notes: %v\n", err) + os.Exit(1) + } + summary, err := summarizeReleaseNotes(notes, summarizer) + if err != nil { + fmt.Printf("Failed to summarize release notes: %v\n", err) + } + fmt.Println(summary) + } + if err := updater.Install(newestVersion); err != nil { + fmt.Printf("Failed to update '%s': %v\n", sw.Name(), err) + os.Exit(1) + } + fmt.Printf("Software '%s' updated successfully.\n", sw.Name()) + } + } + + }, +} + +func init() { + SoftwareCmd.AddCommand(updateCmd) + +} + +func checkForUpdates(updater software.Updateable) (string, error) { + currentVersion, err := updater.GetVersion() + if err != nil { + return "", err + } + remoteVersion, err := updater.GetRemoteVersion() + if err != nil { + return "", err + } + + if currentVersion != remoteVersion { + return remoteVersion, nil + } + return "", nil +} + +func summarizeReleaseNotes(notes string, summarizer software.Summarizer) (string, error) { + var summary string + buffer := bytes.NewBufferString(summary) + summarizer.Summarize(context.Background(), strings.NewReader(notes), buffer) + return buffer.String(), nil +} diff --git a/main.go b/main.go index 5a52a0c..2220812 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "github.com/Print-and-Panic/panic-cli/cmd" _ "github.com/Print-and-Panic/panic-cli/cmd/persona" + _ "github.com/Print-and-Panic/panic-cli/cmd/software" ) func main() {