Skip to content

Commit c811fa0

Browse files
CR-6830-empty-samples (#144)
* add sample-install flag and wizard fixed cursor * documentation version bump
1 parent 6622c18 commit c811fa0

File tree

6 files changed

+76
-37
lines changed

6 files changed

+76
-37
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.133
1+
VERSION=v0.0.134
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/common.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,32 @@ func IsValid(s string) (bool, error) {
7474
return regexp.MatchString(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`, s)
7575
}
7676

77+
func askUserIfToInstallCodefreshSamples(cmd *cobra.Command, sampleInstall *bool) error {
78+
if !store.Get().Silent && !cmd.Flags().Changed("sample-install") {
79+
templates := &promptui.SelectTemplates{
80+
Selected: "{{ . | yellow }} ",
81+
}
82+
83+
labelStr := fmt.Sprintf("%vInstall codefresh samples?%v", CYAN, COLOR_RESET)
84+
85+
prompt := promptui.Select{
86+
Label: labelStr,
87+
Items: []string {"Yes (default)", "No"},
88+
Templates: templates,
89+
}
90+
91+
_, result, err := prompt.Run()
92+
if err != nil {
93+
return fmt.Errorf("Prompt error: %w", err)
94+
}
95+
96+
if result == "No" {
97+
*sampleInstall = false
98+
}
99+
}
100+
return nil
101+
}
102+
77103
func ensureRepo(cmd *cobra.Command, runtimeName string, cloneOpts *git.CloneOptions, fromAPI bool) error {
78104
ctx := cmd.Context()
79105
if cloneOpts.Repo == "" {
@@ -127,6 +153,7 @@ func getRuntimeNameFromUserInput(runtimeName *string) error {
127153
runtimeNamePrompt := promptui.Prompt{
128154
Label: "Runtime name",
129155
Default: "codefresh",
156+
Pointer: promptui.PipeCursor,
130157
}
131158
runtimeNameInput, err := runtimeNamePrompt.Run()
132159
if err != nil {

cmd/commands/runtime.go

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"fmt"
2020
"os"
21+
"strconv"
2122
"strings"
2223
"sync"
2324
"time"
@@ -63,15 +64,16 @@ import (
6364

6465
type (
6566
RuntimeInstallOptions struct {
66-
RuntimeName string
67-
RuntimeToken string
68-
IngressHost string
69-
Insecure bool
70-
Version *semver.Version
71-
GsCloneOpts *git.CloneOptions
72-
InsCloneOpts *git.CloneOptions
73-
KubeFactory kube.Factory
74-
CommonConfig *runtime.CommonConfig
67+
RuntimeName string
68+
RuntimeToken string
69+
IngressHost string
70+
Insecure bool
71+
SampleInstall bool
72+
Version *semver.Version
73+
GsCloneOpts *git.CloneOptions
74+
InsCloneOpts *git.CloneOptions
75+
KubeFactory kube.Factory
76+
CommonConfig *runtime.CommonConfig
7577
}
7678
RuntimeUninstallOptions struct {
7779
RuntimeName string
@@ -113,12 +115,13 @@ func NewRuntimeCommand() *cobra.Command {
113115

114116
func NewRuntimeInstallCommand() *cobra.Command {
115117
var (
116-
runtimeName string
117-
ingressHost string
118-
versionStr string
119-
f kube.Factory
120-
insCloneOpts *git.CloneOptions
121-
gsCloneOpts *git.CloneOptions
118+
runtimeName string
119+
ingressHost string
120+
versionStr string
121+
f kube.Factory
122+
insCloneOpts *git.CloneOptions
123+
gsCloneOpts *git.CloneOptions
124+
sampleInstall bool
122125
finalParameters map[string]string
123126
)
124127

@@ -145,14 +148,14 @@ func NewRuntimeInstallCommand() *cobra.Command {
145148
if len(args) > 0 {
146149
runtimeName = args[0]
147150
}
148-
151+
149152
if !store.Get().Silent && runtimeName == "" {
150153
err := getRuntimeNameFromUserInput(&runtimeName)
151154
if err != nil {
152155
return fmt.Errorf("%w", err)
153156
}
154157
}
155-
158+
156159
if runtimeName == "" {
157160
log.G(ctx).Fatal("must enter a runtime name")
158161
}
@@ -167,13 +170,19 @@ func NewRuntimeInstallCommand() *cobra.Command {
167170
return fmt.Errorf("%w", err)
168171
}
169172

173+
err = askUserIfToInstallCodefreshSamples(cmd, &sampleInstall)
174+
if err != nil {
175+
return fmt.Errorf("%w", err)
176+
}
177+
170178
if gsCloneOpts.Auth.Password == "" {
171179
gsCloneOpts.Auth.Password = insCloneOpts.Auth.Password
172180
}
173181

174182
finalParameters = map[string]string{
175-
"Runtime name": runtimeName,
183+
"Runtime name": runtimeName,
176184
"Repository URL": insCloneOpts.Repo,
185+
"Installing sample resources": strconv.FormatBool(sampleInstall),
177186
}
178187

179188
insCloneOpts.Parse()
@@ -218,13 +227,14 @@ func NewRuntimeInstallCommand() *cobra.Command {
218227
gsCloneOpts.Parse()
219228

220229
return RunRuntimeInstall(ctx, &RuntimeInstallOptions{
221-
RuntimeName: runtimeName,
222-
IngressHost: ingressHost,
223-
Version: version,
224-
Insecure: true,
225-
GsCloneOpts: gsCloneOpts,
226-
InsCloneOpts: insCloneOpts,
227-
KubeFactory: f,
230+
RuntimeName: runtimeName,
231+
IngressHost: ingressHost,
232+
Version: version,
233+
Insecure: true,
234+
SampleInstall: sampleInstall,
235+
GsCloneOpts: gsCloneOpts,
236+
InsCloneOpts: insCloneOpts,
237+
KubeFactory: f,
228238
CommonConfig: &runtime.CommonConfig{
229239
CodefreshBaseURL: cfConfig.GetCurrentContext().URL,
230240
},
@@ -234,6 +244,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
234244

235245
cmd.Flags().StringVar(&ingressHost, "ingress-host", "", "The ingress host")
236246
cmd.Flags().StringVar(&versionStr, "version", "", "The runtime version to install, defaults to latest")
247+
cmd.Flags().BoolVar(&sampleInstall, "sample-install", true, "Installs sample resources, defaults to true")
237248
cmd.Flags().DurationVar(&store.Get().WaitTimeout, "wait-timeout", store.Get().WaitTimeout, "How long to wait for the runtime components to be ready")
238249

239250
insCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{
@@ -366,7 +377,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
366377
GsCloneOpts: opts.GsCloneOpts,
367378
GsName: store.Get().GitSourceName,
368379
RuntimeName: opts.RuntimeName,
369-
CreateDemoResources: true,
380+
CreateDemoResources: opts.SampleInstall,
370381
}); err != nil {
371382
return fmt.Errorf("failed to create `%s`: %w", store.Get().GitSourceName, err)
372383
}
@@ -647,14 +658,14 @@ func NewRuntimeUninstallCommand() *cobra.Command {
647658
if err != nil {
648659
return fmt.Errorf("%w", err)
649660
}
650-
661+
651662
err = ensureGitToken(cmd, cloneOpts)
652663
if err != nil {
653664
return fmt.Errorf("%w", err)
654665
}
655-
666+
656667
finalParameters = map[string]string{
657-
"Runtime name": runtimeName,
668+
"Runtime name": runtimeName,
658669
"Repository URL": cloneOpts.Repo,
659670
}
660671

@@ -752,9 +763,9 @@ func deleteRuntimeFromPlatform(ctx context.Context, opts *RuntimeUninstallOption
752763

753764
func NewRuntimeUpgradeCommand() *cobra.Command {
754765
var (
755-
runtimeName string
756-
versionStr string
757-
cloneOpts *git.CloneOptions
766+
runtimeName string
767+
versionStr string
768+
cloneOpts *git.CloneOptions
758769
finalParameters map[string]string
759770
)
760771

@@ -792,7 +803,7 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
792803
}
793804

794805
finalParameters = map[string]string{
795-
"Runtime name": runtimeName,
806+
"Runtime name": runtimeName,
796807
"Repository URL": cloneOpts.Repo,
797808
}
798809

docs/commands/cli-v2_runtime_install.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ cli-v2 runtime install [runtime_name] [flags]
4040
-n, --namespace string If present, the namespace scope for this CLI request
4141
--provider string The git provider, one of: gitea|github
4242
--repo string Repository URL [GIT_REPO]
43+
--sample-install Installs sample resources, defaults to true (default true)
4344
--version string The runtime version to install, defaults to latest
4445
--wait-timeout duration How long to wait for the runtime components to be ready (default 8m0s)
4546
```

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ cf version
2020
### Linux
2121
```bash
2222
# download and extract the binary
23-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.133/cf-linux-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.134/cf-linux-amd64.tar.gz | tar zx
2424

2525
# move the binary to your $PATH
2626
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -32,7 +32,7 @@ cf version
3232
### Mac
3333
```bash
3434
# download and extract the binary
35-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.133/cf-darwin-amd64.tar.gz | tar zx
35+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.134/cf-darwin-amd64.tar.gz | tar zx
3636

3737
# move the binary to your $PATH
3838
mv ./cf-darwin-amd64 /usr/local/bin/cf

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.133
8+
version: 0.0.134
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

0 commit comments

Comments
 (0)