commands: Fix golint issues

commands/hugo.go:65:1: exported method Response.IsUserError should have comment or be unexported
commands/import_jekyll.go💯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
This commit is contained in:
Cameron Moore 2018-09-06 10:53:18 -05:00 committed by Bjørn Erik Pedersen
parent be3ae3ec92
commit f0effac804
3 changed files with 29 additions and 27 deletions

View file

@ -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)
}

View file

@ -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")
}
}

View file

@ -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)
}