From 7ebdadbbab07f10b9f039726917a34412d0a100c Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Fri, 19 Feb 2016 20:58:56 +0000 Subject: [PATCH 1/2] close #46; needs doc update --- config/config.go | 18 ++++++++---------- utils/utils.go | 1 - 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/config/config.go b/config/config.go index 8ea436e8..20332902 100644 --- a/config/config.go +++ b/config/config.go @@ -42,21 +42,19 @@ func ParseHugo(c *setup.Controller) (*Config, error) { conf.Styles = strings.TrimPrefix(conf.Styles, "/") // Add a beginning slash to make a conf.Styles = "/" + conf.Styles - case "args": - if !c.NextArg() { - return nil, c.ArgErr() + default: + key := "--" + c.Val() + value := "true" + + if c.NextArg() { + value = c.Val() } - // Get the arguments and split the array - args := strings.Split(c.Val(), " ") - for index, element := range args { - args[index] = strings.Replace(element, "\"", "", -1) - } - - conf.Args = args + conf.Args = append(conf.Args, key, value) } } } + conf.Args = append([]string{"--source", conf.Path}, conf.Args...) return conf, nil } diff --git a/utils/utils.go b/utils/utils.go index 5716dac9..638d723f 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -170,7 +170,6 @@ func Run(c *config.Config) { commands.MainSite = nil viper.Reset() - c.Args = append([]string{"--source", c.Path}, c.Args...) commands.HugoCmd.ParseFlags(c.Args) if err := commands.HugoCmd.RunE(nil, nil); err != nil { log.Print(err) From 01e1715bc70c6716c1d903204312d692c9377677 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 20 Feb 2016 08:46:48 +0000 Subject: [PATCH 2/2] improve error logging --- browse/delete.go | 1 - browse/post.go | 7 ------- editor/post.go | 3 --- hugo.go | 5 +++++ utils/utils.go | 2 +- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/browse/delete.go b/browse/delete.go index dc7ff36e..6e008ce3 100644 --- a/browse/delete.go +++ b/browse/delete.go @@ -28,7 +28,6 @@ func DELETE(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro // Check for errors if err != nil { - w.Write([]byte(err.Error())) return 500, err } } else { diff --git a/browse/post.go b/browse/post.go index 821be4c9..0c56cd7e 100644 --- a/browse/post.go +++ b/browse/post.go @@ -63,7 +63,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) if _, err := os.Stat(archetype + ".markdown"); err == nil { err = utils.CopyFile(archetype+".markdown", filename) if err != nil { - w.Write([]byte(err.Error())) return http.StatusInternalServerError, err } @@ -77,7 +76,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) if _, err := os.Stat(archetype + ".md"); err == nil { err = utils.CopyFile(archetype+".md", filename) if err != nil { - w.Write([]byte(err.Error())) return http.StatusInternalServerError, err } @@ -90,7 +88,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) wf, err := os.Create(filename) if err != nil { - w.Write([]byte(err.Error())) return http.StatusInternalServerError, err } @@ -106,7 +103,6 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro // Parse the multipart form in the request err := r.ParseMultipartForm(100000) if err != nil { - w.Write([]byte(err.Error())) return http.StatusInternalServerError, err } @@ -117,20 +113,17 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro // Open the first file var infile multipart.File if infile, err = hdr.Open(); nil != err { - w.Write([]byte(err.Error())) return http.StatusInternalServerError, err } // Create the file var outfile *os.File if outfile, err = os.Create(c.Path + r.URL.Path + hdr.Filename); nil != err { - w.Write([]byte(err.Error())) return http.StatusInternalServerError, err } // Copy the file content if _, err = io.Copy(outfile, infile); nil != err { - w.Write([]byte(err.Error())) return http.StatusInternalServerError, err } diff --git a/editor/post.go b/editor/post.go index 6e4171bc..abba119d 100644 --- a/editor/post.go +++ b/editor/post.go @@ -34,7 +34,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str case "frontmatter-only": f, code, err := parseFrontMatterOnlyFile(rawFile, filename) if err != nil { - w.Write([]byte(err.Error())) return code, err } @@ -48,7 +47,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str case "complete": f, code, err := parseCompleteFile(r, c, rawFile, filename) if err != nil { - w.Write([]byte(err.Error())) return code, err } @@ -61,7 +59,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str err := ioutil.WriteFile(filename, file, 0666) if err != nil { - w.Write([]byte(err.Error())) return http.StatusInternalServerError, err } diff --git a/hugo.go b/hugo.go index 409ea90f..9d0b679c 100644 --- a/hugo.go +++ b/hugo.go @@ -7,6 +7,7 @@ package hugo import ( + "log" "mime" "net/http" "os" @@ -141,6 +142,10 @@ func (h CaddyHugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error utils.Run(h.Config) } + if err != nil { + log.Panic(err) + } + return code, err } diff --git a/utils/utils.go b/utils/utils.go index 638d723f..bd9388f4 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -172,7 +172,7 @@ func Run(c *config.Config) { viper.Reset() commands.HugoCmd.ParseFlags(c.Args) if err := commands.HugoCmd.RunE(nil, nil); err != nil { - log.Print(err) + log.Panic(err) } }