mirror of
https://github.com/lancatlin/mdsh.git
synced 2026-11-05 19:30:12 +08:00
feat: throw error when shell execution failed
This commit is contained in:
1 parent
6fa452b123
commit
5d58e581d0
2 files changed
+15
-17
No files matched your search
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func (ctx TemplateContext) render(tmpl string, output io.Writer) error {
|
||||
t, err := template.New("foo").Funcs(ctx.funcMap()).Parse(tmpl)
|
||||
t, err := template.New("template").Funcs(ctx.funcMap()).Parse(tmpl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -31,22 +31,22 @@ func (ctx TemplateContext) funcMap() template.FuncMap {
|
||||
}
|
||||
}
|
||||
|
||||
func csvToTable(input string) string {
|
||||
func csvToTable(input string) (string, error) {
|
||||
r := csv.NewReader(strings.NewReader(input))
|
||||
records, err := r.ReadAll()
|
||||
if err != nil {
|
||||
return fmt.Sprintf("> Failed to parse CSV: %s\n> Input: %s\n", err.Error(), input)
|
||||
return "", fmt.Errorf("Failed to parse CSV: %s\n> Input: %s\n", err.Error(), input)
|
||||
}
|
||||
result := ""
|
||||
if len(records) == 0 {
|
||||
return fmt.Sprintf("Error: records is empty: %s\n", input)
|
||||
return "", fmt.Errorf("Error: records is empty: %s\n", input)
|
||||
}
|
||||
result += "| " + strings.Join(records[0], " | ") + " |\n"
|
||||
result += "|" + strings.Repeat(" --- |", len(records[0])) + "\n"
|
||||
for _, row := range records[1:] {
|
||||
result += "| " + strings.Join(row, " | ") + " |\n"
|
||||
}
|
||||
return result
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (ctx TemplateContext) OutputFile(meta TemplateMeta) (output io.WriteCloser, err error) {
|
||||
|
||||
Reference in new issue
Block a user