-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
56 lines (49 loc) · 1.25 KB
/
app.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
package app
import (
"flag"
"fmt"
L "github.com/ryanjarv/msh/pkg/logger"
"github.com/ryanjarv/msh/pkg/types"
"github.com/ryanjarv/msh/pkg/utils"
"os"
)
func GetPipeline(reg types.Registry, stdin *os.File, stdout *os.File, args []string) (App, error) {
L.Debug.Printf("GetPipeline: %s:", args)
var state State
// We need to read the state before we can do anything else.
mshStdin := os.Getenv("MSH_STDIN")
if !utils.IsTTY(stdin) || mshStdin != "" {
var err error
// Hack to allow us to read from a test file in a debugger.
if mshStdin != "" {
stdin, err = os.Open(mshStdin)
if err != nil {
return App{}, fmt.Errorf("run: failed to open stdin: %w", err)
}
}
state, err = ReadState(stdin, reg)
if err != nil {
return App{}, fmt.Errorf("run: failed to read state: %w", err)
}
} else {
state = State{
Steps: []types.Step{},
}
}
return App{
FlagSet: utils.ParseArgs(args),
State: state,
Stdin: stdin,
Stdout: stdout,
Registry: reg,
OsArgs: args,
}, nil
}
type App struct {
*flag.FlagSet `json:"-"`
State State `json:"-"`
Registry types.Registry `json:"-"`
OsArgs []string `json:"-"`
Stdin *os.File `json:"-"`
Stdout *os.File `json:"-"`
}