~egtann/up

ref: e0094c2d396c40d9b217e16605545b83ed0985b4 up/up.go -rw-r--r-- 889 bytes
e0094c2d — Evan Tann update license to openbsd isc 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package up

import (
	"fmt"
	"io"
	"io/ioutil"
)

type CmdName string

// Config represents a parsed Upfile.
type Config struct {
	// Commands available to run grouped by command name.
	Commands map[CmdName]*Cmd

	// DefaultCommand is the first command in the Upfile.
	DefaultCommand CmdName

	// DefaultEnvironment is the first inventory in the Upfile.
	DefaultEnvironment string

	lex      *lexer
	text     string
	indented bool
}

// Cmd to run conditionally if the conditions listed in ExecIf all exit with
// zero.
type Cmd struct {
	// ExecIfs any of the following commands exit with non-zero codes.
	ExecIfs []CmdName

	// Execs these commands in order using the default shell.
	Execs []string
}

func ParseUpfile(rdr io.Reader) (*Config, error) {
	byt, err := ioutil.ReadAll(rdr)
	if err != nil {
		return nil, fmt.Errorf("read all: %w", err)
	}
	return parseUpfile(string(byt))
}