Skip to content

Commit

Permalink
style: lint with go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Jun 7, 2021
1 parent 96e32b6 commit 0fed261
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 85 deletions.
1 change: 0 additions & 1 deletion appimage/release.go
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
package appimage

34 changes: 13 additions & 21 deletions appimage/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import (
"strings"
)


const (
SourceGitHub = "git.github"
SourceGitHub = "git.github"
SourceDirectURL = "raw.url"
SourceZapIndex = "idx.zap"
SourceZapIndex = "idx.zap"
)

type SourceMetadata struct {
Expand All @@ -30,24 +29,23 @@ type SourceMetadata struct {
}

type Source struct {
Identifier string `json:"identifier,omitempty"`
Meta SourceMetadata `json:"meta,omitempty"`
Identifier string `json:"identifier,omitempty"`
Meta SourceMetadata `json:"meta,omitempty"`
}

type AppImage struct {
Filepath string `json:"filepath"`
Executable string `json:"executable"`
IconPath string `json:"icon_path,omitempty"`
Filepath string `json:"filepath"`
Executable string `json:"executable"`
IconPath string `json:"icon_path,omitempty"`
IconPathHicolor string `json:"icon_path_hicolor,omitempty"`
DesktopFile string `json:"desktop_file,omitempty"`
Source Source `json:"source"`
DesktopFile string `json:"desktop_file,omitempty"`
Source Source `json:"source"`
}

func (appimage AppImage) getBaseName() string {
return path.Base(appimage.Filepath)
}


/* ExtractThumbnail helps to extract the thumbnails to config.icons directory
* with the apps' basename and png as the Name */
func (appimage *AppImage) ExtractThumbnail(target string) {
Expand Down Expand Up @@ -139,15 +137,15 @@ func (appimage AppImage) Extract(dir string, relPath string) string {
logger.Debugf("Attempt to extract %s was successful, but no target extracted file", relPath)
return ""
} else {
if fileInfo.Mode() & os.ModeSymlink != 0 {
if fileInfo.Mode()&os.ModeSymlink != 0 {
link := fileInfo.Name()
k, err := os.Readlink(dirIcon)

if err != nil {
return ""
}
parts := strings.Split(k, "squashfs-root/")
relPathSymlink := parts[len(parts) - 1]
relPathSymlink := parts[len(parts)-1]
logger.Debugf("%s is a symlink to %s, resolving it.", k, link)
return appimage.Extract(dir, relPathSymlink)

Expand All @@ -156,8 +154,6 @@ func (appimage AppImage) Extract(dir string, relPath string) string {
}
}



}

/* ExtractDesktopFile helps to extract the thumbnails to config.icons directory
Expand All @@ -172,7 +168,7 @@ func (appimage AppImage) ExtractDesktopFile() ([]byte, error) {
defer os.RemoveAll(dir)

logger.Debug("Trying to extract Desktop files")
cmd := exec.Command(appimage.Filepath, "--appimage-extract", "*.desktop")
cmd := exec.Command(appimage.Filepath, "--appimage-extract", "*.desktop")
cmd.Dir = dir

err = cmd.Run()
Expand Down Expand Up @@ -227,7 +223,6 @@ func (appimage AppImage) ExtractDesktopFile() ([]byte, error) {
return data, nil
}


func (appimage *AppImage) ProcessDesktopFile(config config.Store) {
ini.PrettyFormat = false

Expand Down Expand Up @@ -270,9 +265,8 @@ func (appimage *AppImage) ProcessDesktopFile(config config.Store) {
targetDesktopFile := path.Join(config.ApplicationStore, fmt.Sprintf("%s.desktop", appimage.Executable))
logger.Debugf("Preparing %s for writing new desktop file", targetDesktopFile)


// add Exec
desktopEntry.Key("Exec").SetValue(fmt.Sprintf("%s %%U", appimage.Executable ))
desktopEntry.Key("Exec").SetValue(fmt.Sprintf("%s %%U", appimage.Executable))

err = desktopFile.SaveTo(targetDesktopFile)
if err != nil {
Expand All @@ -284,5 +278,3 @@ func (appimage *AppImage) ProcessDesktopFile(config config.Store) {
// and they completed, happily ever after
logger.Debugf("Desktop file successfully written to %s", targetDesktopFile)
}


18 changes: 6 additions & 12 deletions appimage/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func Install(options types.InstallOptions, config config.Store) error {
}
}

if ! options.Silent {
if !options.Silent {
// let the user know what is going to happen next
fmt.Printf("Downloading %s of size %s. \n", tui.Green(asset.Name), tui.Yellow(asset.Size))
confirmDownload := false
Expand Down Expand Up @@ -168,7 +168,7 @@ func Install(options types.InstallOptions, config config.Store) error {

app.Source = Source{
Identifier: sourceIdentifier,
Meta: SourceMetadata{
Meta: SourceMetadata{
Slug: sourceSlug,
CrawledOn: time.Now().String(),
},
Expand Down Expand Up @@ -248,7 +248,7 @@ func Upgrade(config config.Store, silent bool) ([]string, error) {
options := types.Options{
Name: apps[i],
Executable: apps[i],
Silent: silent,
Silent: silent,
}
_, err := update(options, config)

Expand All @@ -270,7 +270,6 @@ func Upgrade(config config.Store, silent bool) ([]string, error) {
return updatedApps, nil
}


// Update method is a safe wrapper script which exposes update to the Command Line interface
// also handles those appimages which are up to date
func Update(options types.Options, config config.Store) error {
Expand Down Expand Up @@ -318,8 +317,6 @@ func RemoveAndInstall(options types.InstallOptions, config config.Store, app *Ap
return app, err
}



func update(options types.Options, config config.Store) (*AppImage, error) {
logger.Debugf("Bootstrapping updater", options.Name)
app := &AppImage{}
Expand All @@ -342,7 +339,7 @@ func update(options types.Options, config config.Store) (*AppImage, error) {
return app, err
}

if ! checkIfUpdateInformationExists(app.Filepath) {
if !checkIfUpdateInformationExists(app.Filepath) {

logger.Debug("This app has no update information embedded")

Expand Down Expand Up @@ -380,7 +377,6 @@ func update(options types.Options, config config.Store) (*AppImage, error) {
return nil, errors.New("appimage has no update information")
}


}
}

Expand Down Expand Up @@ -429,7 +425,6 @@ func update(options types.Options, config config.Store) (*AppImage, error) {
return app, nil
}


// checkIfUpdateInformationExists checks if the appimage contains Update Information
// adapted directly from https://github.com/AppImageCrafters/appimage-update
func checkIfUpdateInformationExists(f string) bool {
Expand Down Expand Up @@ -491,7 +486,7 @@ func Remove(options types.RemoveOptions, config config.Store) error {
os.Remove(app.DesktopFile)
}

binDir := path.Join(xdg.Home, ".local", "bin")
binDir := path.Join(xdg.Home, ".local", "bin")
binFile := path.Join(binDir, options.Executable)

if helpers.CheckIfFileExists(binFile) {
Expand All @@ -504,11 +499,10 @@ func Remove(options types.RemoveOptions, config config.Store) error {
}
}

logger.Debugf("Removing appimage, %s", app.Filepath)
logger.Debugf("Removing appimage, %s", app.Filepath)
bar.Describe("Removing AppImage")
_ = os.Remove(app.Filepath)


logger.Debugf("Removing index file, %s", indexFile)
_ = os.Remove(indexFile)

Expand Down
6 changes: 2 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ type Store struct {

const (
IntegrateAlways = "yes"
IntegrateNever = "no"
IntegrateAsk = "ask"
IntegrateNever = "no"
IntegrateAsk = "ask"
)


func (store *Store) populateDefaults() {
localStore, err := xdg.DataFile("zap/v2")
iconStore, err_ := xdg.DataFile("zap/v2/icons")
Expand Down Expand Up @@ -156,7 +155,6 @@ func NewZapConfig(configPath string) (*Store, error) {
return defStore, nil
}


// NewZapConfigInteractive helps to create an interactive command line
// interface.
func NewZapConfigInteractive(configPath string) (*Store, error) {
Expand Down
1 change: 0 additions & 1 deletion config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ package config
import "github.com/srevinsaju/zap/logging"

var logger = logging.GetLogger()

2 changes: 1 addition & 1 deletion config/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ func GetPath() string {
zapConfigPath = zapXdgCompliantConfigPath
}
return zapConfigPath
}
}
4 changes: 1 addition & 3 deletions daemon/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ func CheckIfRunningSystemd() bool {
return false
}



// CheckIfInvokedBySystemd returns true if this process has been invoked
// by systemd directly or indirectly, false in case it hasn't, the system is not
// using systemd, or we are not sure
Expand All @@ -44,4 +42,4 @@ func CheckIfInvokedBySystemd() bool {
}
log.Println("Probably not launched by systemd (please file an issue if this is wrong)")
return false
}
}
6 changes: 1 addition & 5 deletions daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ var logger = logging.GetLogger()

type UpdateFunction func() ([]string, error)


func upgrade(c chan int, s chan os.Signal, updater UpdateFunction) {

for {
select {
case <- c:
case <-c:
apps, _ := updater()
if len(apps) > 0 {
logger.Infof("Apps have been updated, %s", apps)
Expand All @@ -34,7 +33,6 @@ func upgrade(c chan int, s chan os.Signal, updater UpdateFunction) {
logger.Infof("All apps up-to-date")
}


case <-s:
fmt.Println("quit")
return
Expand All @@ -61,7 +59,6 @@ func Sync(updater UpdateFunction) {
time.Sleep(time.Hour)
}


}()
upgrade(c, s, updater)
}
Expand All @@ -79,4 +76,3 @@ func waitUntilOnline() {
isOnline = helpers.CheckIfOnline()
}
}

6 changes: 1 addition & 5 deletions daemon/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Description=Zap Updater daemon
After=syslog.target network.target
[Service]
Type=simple
ExecStart=` + self + ` daemon
ExecStart=` + self + ` daemon
LimitNOFILE=65536
RestartSec=3
Restart=always
Expand All @@ -61,7 +61,6 @@ Environment=LAUNCHED_BY_SYSTEMD=1
[Install]
WantedBy=default.target`)


logger.Debugf("Writing zapd.service to %s", pathToServiceDir)
err = ioutil.WriteFile(path.Join(pathToServiceDir, "zapd.service"), systemdService, 0644)
if err != nil {
Expand All @@ -78,8 +77,6 @@ WantedBy=default.target`)
return nil
}



// SetupToRunThroughSystemd checks if this process has been launched through
// systemd on a systemd system and takes appropriate measures if it has not,
// either because systemd was not yet set up to launch it, or because
Expand Down Expand Up @@ -156,4 +153,3 @@ func SetupToRunThroughSystemd() error {
return nil

}

8 changes: 3 additions & 5 deletions index/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strings"
)


func getRelease(releases []*github.RepositoryRelease, tag string) *github.RepositoryRelease {
for i := range releases {
if *releases[i].TagName == tag {
Expand All @@ -31,7 +30,6 @@ func getAsset(assets []*github.ReleaseAsset, name string) *github.ReleaseAsset {
return nil
}


func GitHubSurveyUserReleases(options types.InstallOptions, config config.Store) (types.ZapDlAsset, error) {
var asset types.ZapDlAsset

Expand All @@ -40,7 +38,7 @@ func GitHubSurveyUserReleases(options types.InstallOptions, config config.Store)

slugProcessed := strings.Split(options.From, "/")

owner, repo := slugProcessed[len(slugProcessed) - 2], slugProcessed[len(slugProcessed) - 1]
owner, repo := slugProcessed[len(slugProcessed)-2], slugProcessed[len(slugProcessed)-1]
logger.Debugf("Fetching releases from %s/%s", owner, repo)

releases, _, err := client.Repositories.ListReleases(context.Background(), owner, repo, &github.ListOptions{})
Expand Down Expand Up @@ -113,7 +111,7 @@ func GitHubSurveyUserReleases(options types.InstallOptions, config config.Store)
return types.ZapDlAsset{
Name: *assetGitHub.Name,
Download: *assetGitHub.BrowserDownloadURL,
Size: strconv.Itoa(*assetGitHub.Size / 1_000_000) + " MB",
Size: strconv.Itoa(*assetGitHub.Size/1_000_000) + " MB",
}, err

}
}
2 changes: 1 addition & 1 deletion index/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import (
"github.com/srevinsaju/zap/logging"
)

var logger = logging.GetLogger()
var logger = logging.GetLogger()
7 changes: 2 additions & 5 deletions index/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func GetZapReleases(executable string, config config.Store) (*types.ZapReleases,
return zapReleases, nil
}


func ZapSurveyUserReleases(options types.InstallOptions, config config.Store) (types.ZapDlAsset, error) {

asset := types.ZapDlAsset{}
Expand Down Expand Up @@ -162,7 +161,7 @@ func ZapSurveyUserReleases(options types.InstallOptions, config config.Store) (t
// do not show the options when the user are requested silence
return types.ZapDlAsset{}, exceptions.SilenceRequestedError

} else {
} else {
// there are a lot of items in the release, hmm...
logger.Debug("Preparing survey for release selection")
releasePrompt := &survey.Select{
Expand All @@ -184,10 +183,8 @@ func ZapSurveyUserReleases(options types.InstallOptions, config config.Store) (t
return types.ZapDlAsset{}, err
}


logger.Debugf("Running on GOARCH: %s", runtime.GOARCH)


var filteredAssets map[string]types.ZapDlAsset
if options.DoNotFilter == true {
logger.Debug("Explicitly not filtering")
Expand Down Expand Up @@ -224,4 +221,4 @@ func ZapSurveyUserReleases(options types.InstallOptions, config config.Store) (t

logger.Debug(asset)
return asset, nil
}
}
Loading

0 comments on commit 0fed261

Please sign in to comment.