LoadStackFromPath loads a stack from the specified path.
(path string)
| 51 | |
| 52 | // LoadStackFromPath loads a stack from the specified path. |
| 53 | func LoadStackFromPath(path string) (*Stack, error) { |
| 54 | stack := &Stack{} |
| 55 | |
| 56 | f, err := os.Open(path) |
| 57 | if err != nil { |
| 58 | return nil, errors.New("stack not found") |
| 59 | } |
| 60 | |
| 61 | data, err := io.ReadAll(f) |
| 62 | if err != nil { |
| 63 | return nil, err |
| 64 | } |
| 65 | |
| 66 | err = yaml.Unmarshal(data, stack) |
| 67 | if err != nil { |
| 68 | return nil, err |
| 69 | } |
| 70 | |
| 71 | if stack.Name == "" || stack.Base == "" || stack.PkgManager == "" { |
| 72 | return nil, errors.New("invalid stack file") |
| 73 | } |
| 74 | |
| 75 | return stack, nil |
| 76 | } |
| 77 | |
| 78 | // Save saves the stack to a YAML file. |
| 79 | func (stack *Stack) Save() error { |