Correct initialisms as suggested by golint

First step to use initialisms that golint suggests,
for example:

    Line 116: func GetHtmlRenderer should be GetHTMLRenderer

as see on http://goreportcard.com/report/spf13/hugo

Thanks to @bep for the idea!

Note that command-line flags (cobra and pflag)
as well as struct fields like .BaseUrl and .Url
that are used in Go HTML templates need more work
to maintain backward-compatibility, and thus
are NOT yet dealt with in this commit.

First step in fixing #959.
This commit is contained in:
Anthony Fok
2015-03-11 11:34:57 -06:00
committed by bep
parent 00f07c5374
commit 67df33f500
33 changed files with 310 additions and 303 deletions

View File

@@ -56,8 +56,8 @@ Complete documentation is available at http://gohugo.io`,
var hugoCmdV *cobra.Command
//Flags that are to be added to commands.
var BuildWatch, IgnoreCache, Draft, Future, UglyUrls, Verbose, Logging, VerboseLog, DisableRSS, DisableSitemap, PluralizeListTitles, NoTimes bool
var Source, CacheDir, Destination, Theme, BaseUrl, CfgFile, LogFile, Editor string
var BuildWatch, IgnoreCache, Draft, Future, UglyURLs, Verbose, Logging, VerboseLog, DisableRSS, DisableSitemap, PluralizeListTitles, NoTimes bool
var Source, CacheDir, Destination, Theme, BaseURL, CfgFile, LogFile, Editor string
//Execute adds all child commands to the root command HugoCmd and sets flags appropriately.
func Execute() {
@@ -89,8 +89,8 @@ func init() {
HugoCmd.PersistentFlags().StringVarP(&Destination, "destination", "d", "", "filesystem path to write files to")
HugoCmd.PersistentFlags().StringVarP(&Theme, "theme", "t", "", "theme to use (located in /themes/THEMENAME/)")
HugoCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
HugoCmd.PersistentFlags().BoolVar(&UglyUrls, "uglyUrls", false, "if true, use /filename.html instead of /filename/")
HugoCmd.PersistentFlags().StringVarP(&BaseUrl, "baseUrl", "b", "", "hostname (and path) to the root eg. http://spf13.com/")
HugoCmd.PersistentFlags().BoolVar(&UglyURLs, "uglyUrls", false, "if true, use /filename.html instead of /filename/")
HugoCmd.PersistentFlags().StringVarP(&BaseURL, "baseUrl", "b", "", "hostname (and path) to the root eg. http://spf13.com/")
HugoCmd.PersistentFlags().StringVar(&CfgFile, "config", "", "config file (default is path/config.yaml|json|toml)")
HugoCmd.PersistentFlags().StringVar(&Editor, "editor", "", "edit new content with this editor, if provided")
HugoCmd.PersistentFlags().BoolVar(&Logging, "log", false, "Enable Logging")
@@ -127,10 +127,10 @@ func InitializeConfig() {
viper.SetDefault("DefaultLayout", "post")
viper.SetDefault("BuildDrafts", false)
viper.SetDefault("BuildFuture", false)
viper.SetDefault("UglyUrls", false)
viper.SetDefault("UglyURLs", false)
viper.SetDefault("Verbose", false)
viper.SetDefault("IgnoreCache", false)
viper.SetDefault("CanonifyUrls", false)
viper.SetDefault("CanonifyURLs", false)
viper.SetDefault("Taxonomies", map[string]string{"tag": "tags", "category": "categories"})
viper.SetDefault("Permalinks", make(hugolib.PermalinkOverrides, 0))
viper.SetDefault("Sitemap", hugolib.Sitemap{Priority: -1})
@@ -155,7 +155,7 @@ func InitializeConfig() {
}
if hugoCmdV.PersistentFlags().Lookup("uglyUrls").Changed {
viper.Set("UglyUrls", UglyUrls)
viper.Set("UglyURLs", UglyURLs)
}
if hugoCmdV.PersistentFlags().Lookup("disableRSS").Changed {
@@ -181,14 +181,14 @@ func InitializeConfig() {
if hugoCmdV.PersistentFlags().Lookup("logFile").Changed {
viper.Set("LogFile", LogFile)
}
if BaseUrl != "" {
if !strings.HasSuffix(BaseUrl, "/") {
BaseUrl = BaseUrl + "/"
if BaseURL != "" {
if !strings.HasSuffix(BaseURL, "/") {
BaseURL = BaseURL + "/"
}
viper.Set("BaseUrl", BaseUrl)
viper.Set("BaseURL", BaseURL)
}
if viper.GetString("BaseUrl") == "" {
if viper.GetString("BaseURL") == "" {
jww.ERROR.Println("No 'baseurl' set in configuration or as a flag. Features like page menus will not work without one.")
}

View File

@@ -84,11 +84,11 @@ func server(cmd *cobra.Command, args []string) {
viper.Set("port", serverPort)
BaseUrl, err := fixUrl(BaseUrl)
BaseURL, err := fixURL(BaseURL)
if err != nil {
jww.ERROR.Fatal(err)
}
viper.Set("BaseUrl", BaseUrl)
viper.Set("BaseURL", BaseURL)
if err := memStats(); err != nil {
jww.ERROR.Println("memstats error:", err)
@@ -114,9 +114,9 @@ func serve(port int) {
httpFs := &afero.HttpFs{SourceFs: hugofs.DestinationFS}
fileserver := http.FileServer(httpFs.Dir(helpers.AbsPathify(viper.GetString("PublishDir"))))
u, err := url.Parse(viper.GetString("BaseUrl"))
u, err := url.Parse(viper.GetString("BaseURL"))
if err != nil {
jww.ERROR.Fatalf("Invalid BaseUrl: %s", err)
jww.ERROR.Fatalf("Invalid BaseURL: %s", err)
}
if u.Path == "" || u.Path == "/" {
http.Handle("/", fileserver)
@@ -137,10 +137,10 @@ func serve(port int) {
// fixUrl massages the BaseUrl into a form needed for serving
// all pages correctly.
func fixUrl(s string) (string, error) {
func fixURL(s string) (string, error) {
useLocalhost := false
if s == "" {
s = viper.GetString("BaseUrl")
s = viper.GetString("BaseURL")
useLocalhost = true
}
if !strings.HasPrefix(s, "http://") && !strings.HasPrefix(s, "https://") {

View File

@@ -6,11 +6,11 @@ import (
"github.com/spf13/viper"
)
func TestFixUrl(t *testing.T) {
func TestFixURL(t *testing.T) {
type data struct {
TestName string
CliBaseUrl string
CfgBaseUrl string
CLIBaseURL string
CfgBaseURL string
AppendPort bool
Port int
Result string
@@ -28,11 +28,11 @@ func TestFixUrl(t *testing.T) {
}
for i, test := range tests {
BaseUrl = test.CliBaseUrl
viper.Set("BaseUrl", test.CfgBaseUrl)
BaseURL = test.CLIBaseURL
viper.Set("BaseURL", test.CfgBaseURL)
serverAppend = test.AppendPort
serverPort = test.Port
result, err := fixUrl(BaseUrl)
result, err := fixURL(BaseURL)
if err != nil {
t.Errorf("Test #%d %s: unexpected error %s", i, test.TestName, err)
}