Skip to content

Commit

Permalink
Added Debug Flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pegvin committed Mar 22, 2022
1 parent 24941c0 commit 3df7f06
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/commands/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type CleanCmd struct {
}

func (cmd *CleanCmd) Run() (err error) {
func (cmd *CleanCmd) Run(debug bool) (err error) {
appTempDir, err := utils.MakeTempAppDirPath()
if err != nil {
return err
Expand Down
39 changes: 31 additions & 8 deletions src/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"bread/src/helpers/repos"
"bread/src/helpers/utils"
"github.com/DEVLOPRR/libappimage-go"

"errors"
"fmt"
Expand All @@ -16,7 +17,7 @@ type InstallCmd struct {
}

// Function Which Will Be Called When `install` is the Command.
func (cmd *InstallCmd) Run() (err error) {
func (cmd *InstallCmd) Run(debug bool) (err error) {
// Parse The user input
repo, err := repos.ParseTarget(cmd.Target)
if err != nil {
Expand Down Expand Up @@ -53,10 +54,10 @@ func (cmd *InstallCmd) Run() (err error) {
}

// Add The Current Application To The Registry `.registry.json`
cmd.addToRegistry(targetFilePath, repo)
cmd.addToRegistry(targetFilePath, repo, debug)

// Integrated The AppImage To Desktop
cmd.createDesktopIntegration(targetFilePath)
cmd.createDesktopIntegration(targetFilePath, debug)

// Print Signature Info If Exist.
utils.ShowSignature(targetFilePath)
Expand All @@ -65,37 +66,59 @@ func (cmd *InstallCmd) Run() (err error) {
}

// Function To Add Installed Program To Registry (Installed App information is stored in here).
func (cmd *InstallCmd) addToRegistry(targetFilePath string, repo repos.Application) {
func (cmd *InstallCmd) addToRegistry(targetFilePath string, repo repos.Application, debug bool) (error) {
sha1, _ := utils.GetFileSHA1(targetFilePath) // Get The Sha1 Hash
updateInfo, _ := utils.ReadUpdateInfo(targetFilePath) // Get The UpdateInfo
if updateInfo == "" {
updateInfo = repo.FallBackUpdateInfo()
}

appimageInfo, err := getAppImageInfo(targetFilePath, debug)
if err != nil {
return err
}

// Make a new entry struct
entry := utils.RegistryEntry{
FilePath: targetFilePath,
Repo: repo.Id(),
FileSha1: sha1,
AppName: "",
AppVersion: "",
FilePath: targetFilePath,
UpdateInfo: updateInfo,
IsTerminalApp: appimageInfo.IsTerminalApp,
AppImageType: appimageInfo.AppImageType,
}

registry, _ := utils.OpenRegistry() // Open The Registry
if registry != nil {
_ = registry.Add(entry) // Add the entry to registry `.registry.json`
_ = registry.Close() // Close the registry
}
return nil
}

func getAppImageInfo(targetFilePath string, debug bool) (*utils.AppImageInfo, error) {
libAppImage, err := libappimagego.NewLibAppImageBindings() // Load the `libappimage` Library For Integration
if err != nil {
return nil, err
}

return &utils.AppImageInfo{
IsTerminalApp: libAppImage.IsTerminalApp(targetFilePath),
AppImageType: libAppImage.GetType(targetFilePath, debug),
}, nil
}

// Function To Integrate The AppImage To Desktop. (Can Only Be Called From InstallCmd Struct)
func (cmd *InstallCmd) createDesktopIntegration(targetFilePath string) {
libAppImage, err := utils.NewLibAppImageBindings() // Load the `libappimage` Library For Integration
func (cmd *InstallCmd) createDesktopIntegration(targetFilePath string, debug bool) {
libAppImage, err := libappimagego.NewLibAppImageBindings() // Load the `libappimage` Library For Integration
if err != nil {
fmt.Println("Integration failed:", err.Error())
return
}

err = libAppImage.Register(targetFilePath) // Register The File
err = libAppImage.Register(targetFilePath, debug) // Register The File
if err != nil {
fmt.Println("Integration failed: " + err.Error())
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type ListCmd struct {
}

// Function which will be executed when `list` is called.
func (r *ListCmd) Run() error {
func (r *ListCmd) Run(debug bool) error {
registry, err := utils.OpenRegistry() // Open The Registry
if err != nil {
return err
Expand Down
11 changes: 6 additions & 5 deletions src/commands/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"fmt"
"bread/src/helpers/utils"
"github.com/DEVLOPRR/libappimage-go"
"os"
"strings"
)
Expand All @@ -13,7 +14,7 @@ type RemoveCmd struct {
}

// Function which will be executed when `remove` is called.
func (cmd *RemoveCmd) Run() (err error) {
func (cmd *RemoveCmd) Run(debug bool) (err error) {
cmd.Target = strings.ToLower(cmd.Target)
registry, err := utils.OpenRegistry() // Open The Registry
if err != nil {
Expand All @@ -33,7 +34,7 @@ func (cmd *RemoveCmd) Run() (err error) {
return fmt.Errorf("application not found \"" + cmd.Target + "\"")
}

err = removeDesktopIntegration(entry.FilePath) // Remove the application desktop integration
err = removeDesktopIntegration(entry.FilePath, debug) // Remove the application desktop integration
if err != nil {
fmt.Println("Desktop integration removal failed: " + err.Error())
}
Expand All @@ -52,8 +53,8 @@ func (cmd *RemoveCmd) Run() (err error) {
}

// Function which will remove the application desktop integration
func removeDesktopIntegration(filePath string) error {
libAppImage, err := utils.NewLibAppImageBindings()
func removeDesktopIntegration(filePath string, debug bool) error {
libAppImage, err := libappimagego.NewLibAppImageBindings()
if err != nil {
return err
}
Expand All @@ -62,5 +63,5 @@ func removeDesktopIntegration(filePath string) error {
return nil
}

return libAppImage.Unregister(filePath)
return libAppImage.Unregister(filePath, debug)
}
2 changes: 1 addition & 1 deletion src/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func executeCmd(target string, arguments []string) {
<-doneChan
}

func (cmd *RunCmd) Run() (err error) {
func (cmd *RunCmd) Run(debug bool) (err error) {
// Parse The user input
repo, err := repos.ParseTarget(cmd.Target)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type SearchCmd struct {
Name string `arg:"" name:"name" help:"name to search for." type:"string"`
}

func (cmd *SearchCmd) Run() (error) {
func (cmd *SearchCmd) Run(debug bool) (error) {
var err error
fmt.Println("Getting Latest List...")
err = utils.FetchAppImageListJson()
Expand Down
2 changes: 1 addition & 1 deletion src/commands/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type UpdateCmd struct {
var NoUpdateInfo = errors.New("there is no update information")

// Function Which Will Be Executed When `update` is called.
func (cmd *UpdateCmd) Run() (err error) {
func (cmd *UpdateCmd) Run(debug bool) (err error) {
if cmd.All { // if `update all`
cmd.Targets, err = getAllTargets() // Load all the application info into targets
if err != nil {
Expand Down

0 comments on commit 3df7f06

Please sign in to comment.