aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-04-03 04:09:25 +0700
committerShulhan <ms@kilabit.info>2021-04-03 04:40:27 +0700
commitd4dd936694d11a5891167297e9cfd117175b132a (patch)
tree1e5a8676ce282e4f75e3f0634e61421eaa60f370
parent2c1ec60015ed4a29134be4d8ddd1c71d38bf52fa (diff)
downloadciigo-d4dd936694d11a5891167297e9cfd117175b132a.tar.xz
all: changes the Watch signature to use ConvertOptions
Just like changes on Convert function, this is to prevent additional parameter added on Watch function affect the consumer of API in the future.
-rw-r--r--ciigo.go25
1 files changed, 18 insertions, 7 deletions
diff --git a/ciigo.go b/ciigo.go
index 6d590f5..bad8117 100644
--- a/ciigo.go
+++ b/ciigo.go
@@ -148,7 +148,7 @@ func Serve(opts *ServeOptions) (err error) {
}
//
-// Watch any changes on asciidoc files on directory "dir" recursively and
+// Watch any changes on asciidoc files on directory Root recursively and
// changes on the HTML template file.
// If there is new or modified asciidoc files it will convert them into HTML
// files using HTML template automatically.
@@ -157,20 +157,31 @@ func Serve(opts *ServeOptions) (err error) {
// If the HTML template file deleted, it will replace them with internal,
// default HTML template.
//
-func Watch(dir, htmlTemplate string) (err error) {
- htmlg, err := newHTMLGenerator(nil, htmlTemplate, true)
+func Watch(opts *ConvertOptions) (err error) {
+ var (
+ logp = "Watch"
+ htmlg *htmlGenerator
+ w *watcher
+ )
+
+ if opts == nil {
+ opts = &ConvertOptions{}
+ }
+ opts.init()
+
+ htmlg, err = newHTMLGenerator(nil, opts.HtmlTemplate, true)
if err != nil {
- return fmt.Errorf("Watch: %w", err)
+ return fmt.Errorf("%s: %w", logp, err)
}
- w, err := newWatcher(htmlg, dir)
+ w, err = newWatcher(htmlg, opts.Root)
if err != nil {
- return fmt.Errorf("Watch: %w", err)
+ return fmt.Errorf("%s: %w", logp, err)
}
err = w.start()
if err != nil {
- return fmt.Errorf("Watch: %w", err)
+ return fmt.Errorf("%s: %w", logp, err)
}
return nil