annotate zs_util.go @ 31:b2f491299cee draft

dead end with template functions
author zaitsev.serge
date Wed, 02 Sep 2015 14:54:16 +0000
parents d052f3a44195
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
1 package main
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
2
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
3 import (
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
4 "bytes"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
5 "io"
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
6 "io/ioutil"
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
7 "log"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
8 "os"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
9 "os/exec"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
10 "path/filepath"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
11 "strings"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
12 )
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
13
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
14 func makeFuncs(funcs Funcs, vars Vars) Funcs {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
15 f := Funcs{}
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
16 for k, v := range funcs {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
17 f[k] = v
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
18 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
19 for k, v := range vars {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
20 f[k] = varFunc(v)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
21 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
22 // Plugin functions
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
23 files, _ := ioutil.ReadDir(ZSDIR)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
24 for _, file := range files {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
25 if !file.IsDir() {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
26 name := file.Name()
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
27 if !strings.HasSuffix(name, ".html") && !strings.HasSuffix(name, ".amber") {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
28 f[renameExt(name, "", "")] = pluginFunc(name, vars)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
29 } else {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
30 f[renameExt(name, "", "")] = partialFunc(name, f, vars)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
31 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
32 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
33 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
34 return f
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
35 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
36
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
37 func varFunc(s string) func() string {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
38 return func() string {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
39 return s
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
40 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
41 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
42
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
43 func pluginFunc(cmd string, vars Vars) func(args ...string) string {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
44 return func(args ...string) string {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
45 out := bytes.NewBuffer(nil)
24
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
46 if err := run(filepath.Join(ZSDIR, cmd), args, vars, out); err != nil {
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
47 return cmd + ":" + err.Error()
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
48 } else {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
49 return string(out.Bytes())
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
50 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
51 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
52 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
53
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
54 func partialFunc(name string, funcs Funcs, vars Vars) func() string {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
55 return func() string {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
56 var err error
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
57 w := bytes.NewBuffer(nil)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
58 if strings.HasSuffix(name, ".amber") {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
59 err = buildAmber(filepath.Join(ZSDIR, name), w, funcs, vars)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
60 } else {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
61 err = buildHTML(filepath.Join(ZSDIR, name), w, funcs, vars)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
62 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
63 if err != nil {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
64 return name + ":" + err.Error()
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
65 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
66 return string(w.Bytes())
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
67 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
68 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
69
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
70 func builtins() Funcs {
24
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
71 exec := func(cmd string, args ...string) string {
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
72 out := bytes.NewBuffer(nil)
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
73 if err := run(cmd, args, Vars{}, out); err != nil {
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
74 return cmd + ":" + err.Error()
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
75 } else {
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
76 return string(out.Bytes())
d052f3a44195 fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents: 23
diff changeset
77 }
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
78 return ""
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
79 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
80 return Funcs{
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
81 "exec": exec,
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
82 "var": Var,
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
83 "lorem": Lorem,
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
84 "dateparse": DateParse,
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
85 "datefmt": DateFmt,
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
86 "wc": WordCount,
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
87 "ttr": TimeToRead,
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
88 "ls": List,
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
89 "...": func(args ...string) []string {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
90 return append([]string{"..."}, args...)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
91 },
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
92 "sort": func(args ...string) []string {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
93
b2f491299cee dead end with template functions
zaitsev.serge
parents: 24
diff changeset
94 return Sort(args...)
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
95 },
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
96 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
97 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
98
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
99 func renameExt(path, from, to string) string {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
100 if from == "" {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
101 from = filepath.Ext(path)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
102 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
103 if strings.HasSuffix(path, from) {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
104 return strings.TrimSuffix(path, from) + to
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
105 } else {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
106 return path
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
107 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
108 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
109
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
110 func globals() Vars {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
111 vars := Vars{}
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
112 for _, e := range os.Environ() {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
113 pair := strings.Split(e, "=")
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
114 if strings.HasPrefix(pair[0], "ZS_") {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
115 vars[strings.ToLower(pair[0][3:])] = pair[1]
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
116 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
117 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
118 return vars
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
119 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
120
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
121 // Converts zs markdown variables into environment variables
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
122 func env(vars Vars) []string {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
123 env := []string{"ZS=" + os.Args[0], "ZS_OUTDIR=" + PUBDIR}
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
124 env = append(env, os.Environ()...)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
125 if vars != nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
126 for k, v := range vars {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
127 env = append(env, "ZS_"+strings.ToUpper(k)+"="+v)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
128 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
129 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
130 return env
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
131 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
132
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
133 // Runs command with given arguments and variables, intercepts stderr and
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
134 // redirects stdout into the given writer
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
135 func run(cmd string, args []string, vars Vars, output io.Writer) error {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
136 var errbuf bytes.Buffer
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
137 c := exec.Command(cmd, args...)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
138 c.Env = env(vars)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
139 c.Stdout = output
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
140 c.Stderr = &errbuf
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
141
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
142 err := c.Run()
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
143
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
144 if errbuf.Len() > 0 {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
145 log.Println("ERROR:", errbuf.String())
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
146 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
147
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
148 if err != nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
149 return err
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
150 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
151 return nil
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
152 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
153
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
154 // Splits a string in exactly two parts by delimiter
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
155 // If no delimiter is found - the second string is be empty
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
156 func split2(s, delim string) (string, string) {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
157 parts := strings.SplitN(s, delim, 2)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
158 if len(parts) == 2 {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
159 return parts[0], parts[1]
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
160 } else {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
161 return parts[0], ""
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
162 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
163 }