summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorCameron Moore <moorereason@gmail.com>2018-09-06 10:53:18 -0500
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-09-07 08:25:51 +0200
commitf0effac80426325040c4bc703cd610f434d0b5a8 (patch)
tree18c011f77f3777bafef9e00d98df302f0572f22f /commands
parentbe3ae3ec92da972a55112af39ce2e1c45121b9a5 (diff)
commands: Fix golint issues
commands/hugo.go:65:1: exported method Response.IsUserError should have comment or be unexported commands/import_jekyll.go:100:21: error strings should not be capitalized or end with punctuation or a newline commands/server.go:417:1: receiver name sc should be consistent with previous receiver name s for serverCmd
Diffstat (limited to 'commands')
-rw-r--r--commands/hugo.go2
-rw-r--r--commands/import_jekyll.go16
-rw-r--r--commands/server.go38
3 files changed, 29 insertions, 27 deletions
diff --git a/commands/hugo.go b/commands/hugo.go
index a97c28294..3f1697ea9 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -62,6 +62,8 @@ type Response struct {
Cmd *cobra.Command
}
+// IsUserError returns true is the Response error is a user error rather than a
+// system error.
func (r Response) IsUserError() bool {
return r.Err != nil && isUserError(r.Err)
}
diff --git a/commands/import_jekyll.go b/commands/import_jekyll.go
index af8a5acb2..6d88a7fd8 100644
--- a/commands/import_jekyll.go
+++ b/commands/import_jekyll.go
@@ -73,23 +73,23 @@ Import from Jekyll requires two paths, e.g. ` + "`hugo import jekyll jekyll_root
func (i *importCmd) importFromJekyll(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
- return newUserError(`Import from Jekyll requires two paths, e.g. ` + "`hugo import jekyll jekyll_root_path target_path`.")
+ return newUserError(`import from jekyll requires two paths, e.g. ` + "`hugo import jekyll jekyll_root_path target_path`.")
}
jekyllRoot, err := filepath.Abs(filepath.Clean(args[0]))
if err != nil {
- return newUserError("Path error:", args[0])
+ return newUserError("path error:", args[0])
}
targetDir, err := filepath.Abs(filepath.Clean(args[1]))
if err != nil {
- return newUserError("Path error:", args[1])
+ return newUserError("path error:", args[1])
}
jww.INFO.Println("Import Jekyll from:", jekyllRoot, "to:", targetDir)
if strings.HasPrefix(filepath.Dir(targetDir), jekyllRoot) {
- return newUserError("Target path should not be inside the Jekyll root, aborting.")
+ return newUserError("abort: target path should not be inside the Jekyll root")
}
forceImport, _ := cmd.Flags().GetBool("force")
@@ -97,7 +97,7 @@ func (i *importCmd) importFromJekyll(cmd *cobra.Command, args []string) error {
fs := afero.NewOsFs()
jekyllPostDirs, hasAnyPost := i.getJekyllDirInfo(fs, jekyllRoot)
if !hasAnyPost {
- return errors.New("Your Jekyll root contains neither posts nor drafts, aborting.")
+ return errors.New("abort: jekyll root contains neither posts nor drafts")
}
site, err := i.createSiteFromJekyll(jekyllRoot, targetDir, jekyllPostDirs, forceImport)
@@ -120,7 +120,7 @@ func (i *importCmd) importFromJekyll(cmd *cobra.Command, args []string) error {
relPath, err := filepath.Rel(jekyllRoot, path)
if err != nil {
- return newUserError("Get rel path error:", path)
+ return newUserError("get rel path error:", path)
}
relPath = filepath.ToSlash(relPath)
@@ -204,13 +204,13 @@ func (i *importCmd) createSiteFromJekyll(jekyllRoot, targetDir string, jekyllPos
fs := s.Fs.Source
if exists, _ := helpers.Exists(targetDir, fs); exists {
if isDir, _ := helpers.IsDir(targetDir, fs); !isDir {
- return nil, errors.New("Target path \"" + targetDir + "\" already exists but not a directory")
+ return nil, errors.New("target path \"" + targetDir + "\" exists but is not a directory")
}
isEmpty, _ := helpers.IsEmpty(targetDir, fs)
if !isEmpty && !force {
- return nil, errors.New("Target path \"" + targetDir + "\" already exists and is not empty")
+ return nil, errors.New("target path \"" + targetDir + "\" exists and is not empty")
}
}
diff --git a/commands/server.go b/commands/server.go
index fde881f6f..27999fa6c 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -122,27 +122,27 @@ func (f noDirFile) Readdir(count int) ([]os.FileInfo, error) {
var serverPorts []int
-func (s *serverCmd) server(cmd *cobra.Command, args []string) error {
+func (sc *serverCmd) server(cmd *cobra.Command, args []string) error {
// If a Destination is provided via flag write to disk
destination, _ := cmd.Flags().GetString("destination")
if destination != "" {
- s.renderToDisk = true
+ sc.renderToDisk = true
}
var serverCfgInit sync.Once
cfgInit := func(c *commandeer) error {
- c.Set("renderToMemory", !s.renderToDisk)
+ c.Set("renderToMemory", !sc.renderToDisk)
if cmd.Flags().Changed("navigateToChanged") {
- c.Set("navigateToChanged", s.navigateToChanged)
+ c.Set("navigateToChanged", sc.navigateToChanged)
}
if cmd.Flags().Changed("disableLiveReload") {
- c.Set("disableLiveReload", s.disableLiveReload)
+ c.Set("disableLiveReload", sc.disableLiveReload)
}
if cmd.Flags().Changed("disableFastRender") {
- c.Set("disableFastRender", s.disableFastRender)
+ c.Set("disableFastRender", sc.disableFastRender)
}
- if s.serverWatch {
+ if sc.serverWatch {
c.Set("watch", true)
}
@@ -158,25 +158,25 @@ func (s *serverCmd) server(cmd *cobra.Command, args []string) error {
serverPorts = make([]int, 1)
if c.languages.IsMultihost() {
- if !s.serverAppend {
+ if !sc.serverAppend {
err = newSystemError("--appendPort=false not supported when in multihost mode")
}
serverPorts = make([]int, len(c.languages))
}
- currentServerPort := s.serverPort
+ currentServerPort := sc.serverPort
for i := 0; i < len(serverPorts); i++ {
- l, err := net.Listen("tcp", net.JoinHostPort(s.serverInterface, strconv.Itoa(currentServerPort)))
+ l, err := net.Listen("tcp", net.JoinHostPort(sc.serverInterface, strconv.Itoa(currentServerPort)))
if err == nil {
l.Close()
serverPorts[i] = currentServerPort
} else {
- if i == 0 && s.cmd.Flags().Changed("port") {
+ if i == 0 && sc.cmd.Flags().Changed("port") {
// port set explicitly by user -- he/she probably meant it!
err = newSystemErrorF("Server startup failed: %s", err)
}
- jww.ERROR.Println("port", s.serverPort, "already in use, attempting to use an available port")
+ jww.ERROR.Println("port", sc.serverPort, "already in use, attempting to use an available port")
sp, err := helpers.FindAvailablePort()
if err != nil {
err = newSystemError("Unable to find alternative port to use:", err)
@@ -190,9 +190,9 @@ func (s *serverCmd) server(cmd *cobra.Command, args []string) error {
c.serverPorts = serverPorts
- c.Set("port", s.serverPort)
- if s.liveReloadPort != -1 {
- c.Set("liveReloadPort", s.liveReloadPort)
+ c.Set("port", sc.serverPort)
+ if sc.liveReloadPort != -1 {
+ c.Set("liveReloadPort", sc.liveReloadPort)
} else {
c.Set("liveReloadPort", serverPorts[0])
}
@@ -206,7 +206,7 @@ func (s *serverCmd) server(cmd *cobra.Command, args []string) error {
serverPort = serverPorts[0]
}
- baseURL, err := s.fixURL(language, s.baseURL, serverPort)
+ baseURL, err := sc.fixURL(language, sc.baseURL, serverPort)
if err != nil {
return nil
}
@@ -226,7 +226,7 @@ func (s *serverCmd) server(cmd *cobra.Command, args []string) error {
jww.ERROR.Println("memstats error:", err)
}
- c, err := initializeConfig(true, true, &s.hugoBuilderCommon, s, cfgInit)
+ c, err := initializeConfig(true, true, &sc.hugoBuilderCommon, sc, cfgInit)
if err != nil {
return err
}
@@ -240,7 +240,7 @@ func (s *serverCmd) server(cmd *cobra.Command, args []string) error {
}
// Watch runs its own server as part of the routine
- if s.serverWatch {
+ if sc.serverWatch {
watchDirs, err := c.getDirList()
if err != nil {
@@ -266,7 +266,7 @@ func (s *serverCmd) server(cmd *cobra.Command, args []string) error {
}
- return c.serve(s)
+ return c.serve(sc)
}