-
Notifications
You must be signed in to change notification settings - Fork 9
/
framework.go
70 lines (56 loc) · 1.67 KB
/
framework.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package create
import (
"context"
"strings"
"github.com/spf13/cobra"
"namespacelabs.dev/foundation/internal/console/tui"
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/foundation/schema"
)
func selectFramework(ctx context.Context, title string, fmwkFlag string) (*schema.Framework, error) {
frameworks := []frameworkItem{
{schema.Framework_GO, "Go gRPC and HTTP handlers (beta)."},
}
var item frameworkItem
if fmwkFlag != "" {
for _, f := range frameworks {
if strings.ToLower(f.Title()) == fmwkFlag {
item = f
break
}
}
if item.fwmk == 0 {
return nil, fnerrors.New("invalid framework: %s", fmwkFlag)
}
} else {
selected, err := tui.ListSelect(ctx, title, frameworks)
if err != nil {
return nil, err
}
if selected == nil {
return nil, err
}
item = selected.(frameworkItem)
}
return &item.fwmk, nil
}
type frameworkItem struct {
fwmk schema.Framework
desc string
}
func (f frameworkItem) Title() string { return f.fwmk.String() }
func (f frameworkItem) Description() string { return f.desc }
func (f frameworkItem) FilterValue() string { return f.Title() }
func withFramework(fmwkOut *string) *fmwkParser {
return &fmwkParser{fmwkOut: fmwkOut}
}
type fmwkParser struct {
fmwkOut *string
}
func (p *fmwkParser) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(p.fmwkOut, "framework", "", "The framework to use (go or web).")
}
func (p *fmwkParser) Parse(ctx context.Context, args []string) error { return nil }