fix: implement godot's suggestions on app comments
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d32b44aedd
commit
6a2470db54
10
cmd/root.go
10
cmd/root.go
@ -10,10 +10,10 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// appName is the name of the app
|
// appName is the name of the app.
|
||||||
const appName = "go-xkcdreader"
|
const appName = "go-xkcdreader"
|
||||||
|
|
||||||
// Root is the main go-xkcdreader command
|
// Root is the main go-xkcdreader command.
|
||||||
var Root = &cobra.Command{
|
var Root = &cobra.Command{
|
||||||
Use: appName,
|
Use: appName,
|
||||||
Short: "an offline-capable xkcd webcomic reader written in Go",
|
Short: "an offline-capable xkcd webcomic reader written in Go",
|
||||||
@ -24,12 +24,12 @@ var Root = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAppName returns the name of the application
|
// GetAppName returns the name of the application.
|
||||||
func GetAppName() string {
|
func GetAppName() string {
|
||||||
return appName
|
return appName
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute is the entrypoint of cobra's poison
|
// Execute is the entrypoint of cobra's poison.
|
||||||
func Execute() {
|
func Execute() {
|
||||||
if err := Root.Execute(); err != nil {
|
if err := Root.Execute(); err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
@ -38,7 +38,7 @@ func Execute() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// help redefines the original help func, essentially adding a way to exit the
|
// help redefines the original help func, essentially adding a way to exit the
|
||||||
// application properly after showing help message
|
// application properly after showing help message.
|
||||||
func help(*cobra.Command, []string) {
|
func help(*cobra.Command, []string) {
|
||||||
err := Root.Usage()
|
err := Root.Usage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -25,7 +25,7 @@ func TestExecuteRootCmd(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// is this valid? dunno
|
// is this valid? dunno...
|
||||||
func TestExecuteFunc(t *testing.T) {
|
func TestExecuteFunc(t *testing.T) {
|
||||||
Execute()
|
Execute()
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,10 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// version holds app version string
|
// version holds app version string.
|
||||||
var version = "v0.0.13"
|
var version = "v0.0.13"
|
||||||
|
|
||||||
// used to determine whether to print short or long version string
|
// used to determine whether to print short or long version string.
|
||||||
var shortVersion = false
|
var shortVersion = false
|
||||||
|
|
||||||
var cmdVersion = &cobra.Command{
|
var cmdVersion = &cobra.Command{
|
||||||
@ -30,7 +30,7 @@ var cmdVersion = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// get (short if -s/--short flag is supplied) version
|
// get (short if -s/--short flag is supplied) version.
|
||||||
func getVersion() string {
|
func getVersion() string {
|
||||||
if !shortVersion {
|
if !shortVersion {
|
||||||
return appName + " - " + version
|
return appName + " - " + version
|
||||||
@ -38,12 +38,12 @@ func getVersion() string {
|
|||||||
return GetShortVersion()
|
return GetShortVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetShortVersion returns a bare version string
|
// GetShortVersion returns a bare version string.
|
||||||
func GetShortVersion() string {
|
func GetShortVersion() string {
|
||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
// the init func registers the commands and flags with cobra
|
// the init func registers the commands and flags with cobra.
|
||||||
func init() {
|
func init() {
|
||||||
cmdVersion.Flags().BoolVarP(&shortVersion, "short", "s", false, "print just the version string and nothing else")
|
cmdVersion.Flags().BoolVarP(&shortVersion, "short", "s", false, "print just the version string and nothing else")
|
||||||
Root.AddCommand(cmdVersion)
|
Root.AddCommand(cmdVersion)
|
||||||
|
@ -46,7 +46,7 @@ func TestGetVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set shortVersion variable manually
|
// set shortVersion variable manually.
|
||||||
func TestGetVersionWithShortVersionVar(t *testing.T) {
|
func TestGetVersionWithShortVersionVar(t *testing.T) {
|
||||||
shortVersion = true
|
shortVersion = true
|
||||||
want := version
|
want := version
|
||||||
@ -58,7 +58,7 @@ func TestGetVersionWithShortVersionVar(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// explicitly get short version
|
// explicitly get short version.
|
||||||
func TestGetShortVersion(t *testing.T) {
|
func TestGetShortVersion(t *testing.T) {
|
||||||
want := version
|
want := version
|
||||||
got := GetShortVersion()
|
got := GetShortVersion()
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
package xkcdreader
|
package xkcdreader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// for embedding standard license header
|
// for embedding standard license header.
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ const appGreeting = "welcome to go-xkcdreader"
|
|||||||
|
|
||||||
var a fyne.App
|
var a fyne.App
|
||||||
|
|
||||||
// RunApp performs sets up and runs the main application
|
// RunApp performs sets up and runs the main application.
|
||||||
func RunApp() {
|
func RunApp() {
|
||||||
// initialize the fyne application
|
// initialize the fyne application
|
||||||
newApp()
|
newApp()
|
||||||
@ -61,7 +61,7 @@ func getApp() fyne.App {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
// makeGreeting creates a greeting label
|
// makeGreeting creates a greeting label.
|
||||||
func makeGreeting() *widget.Label {
|
func makeGreeting() *widget.Label {
|
||||||
w := widget.NewLabel(appGreeting)
|
w := widget.NewLabel(appGreeting)
|
||||||
w.TextStyle.Monospace = true
|
w.TextStyle.Monospace = true
|
||||||
@ -134,7 +134,7 @@ func makeBrowseUI() *fyne.Container {
|
|||||||
return browseUI
|
return browseUI
|
||||||
}
|
}
|
||||||
|
|
||||||
// get img from filesystem, resize it and return as *canvas.Image
|
// get img from filesystem, resize it and return as *canvas.Image.
|
||||||
func getImg(imgPath string) *canvas.Image {
|
func getImg(imgPath string) *canvas.Image {
|
||||||
_, err := os.Stat(imgPath)
|
_, err := os.Stat(imgPath)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user