Skip to content

Commit d0efad8

Browse files
authored
Merge pull request #712 from onflow/improvement/flowser-path
Change default Flowser path on Windows
2 parents 176063f + ce66279 commit d0efad8

5 files changed

Lines changed: 39 additions & 18 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/onflow/flow-cli/pkg/flowkit v0.0.0-20221123090817-587405125c1f
1414
github.com/onflow/flow-emulator v0.38.1
1515
github.com/onflow/flow-go-sdk v0.29.1
16-
github.com/onflowser/flowser/v2 v2.0.8-beta
16+
github.com/onflowser/flowser/v2 v2.0.9-beta
1717
github.com/pkg/errors v0.9.1
1818
github.com/psiemens/sconfig v0.1.0
1919
github.com/spf13/afero v1.9.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,8 @@ github.com/onflow/nft-storefront/lib/go/contracts v0.0.0-20220714155620-011db20f
711711
github.com/onflow/nft-storefront/lib/go/contracts v0.0.0-20220714155620-011db20fe754/go.mod h1:E3ScfQb5XcWJCIAdtIeEnr5i5l2y60GT0BTXeIHseWg=
712712
github.com/onflow/sdks v0.4.4 h1:aJPGJJLAN+mlBWAQxsyuJXeRRMFeLwU6Mp4e/YL6bdU=
713713
github.com/onflow/sdks v0.4.4/go.mod h1:F0dj0EyHC55kknLkeD10js4mo14yTdMotnWMslPirrU=
714-
github.com/onflowser/flowser/v2 v2.0.8-beta h1:cTnrn4OOsqwI1FrkSKBLs6D8xEHYTKV5q4pgADw2rV0=
715-
github.com/onflowser/flowser/v2 v2.0.8-beta/go.mod h1:g/nfelBOx0A4j60Twsr7GsmKapr2oxtRZQS0lwPHgZY=
714+
github.com/onflowser/flowser/v2 v2.0.9-beta h1:U59WUu/u0ZPDlbFcGs66fVjYektxqeunAPQLK0no2jA=
715+
github.com/onflowser/flowser/v2 v2.0.9-beta/go.mod h1:g/nfelBOx0A4j60Twsr7GsmKapr2oxtRZQS0lwPHgZY=
716716
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
717717
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
718718
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=

internal/settings/defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func getDefaultInstallDir() string {
4848
case Windows:
4949
// https://superuser.com/questions/1327037/what-choices-do-i-have-about-where-to-install-software-on-windows-10
5050
user, _ := user.Current() // safe to ignore cache errors
51-
return fmt.Sprintf(`%s\AppData\Local`, user.HomeDir)
51+
return fmt.Sprintf(`%s\AppData\Local\Programs`, user.HomeDir)
5252
default:
5353
return ""
5454
}

internal/tools/flowser.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,18 @@ func runFlowser(
9797

9898
func installFlowser(flowser *flowser.App, installPath string) (string, error) {
9999
fmt.Println("It looks like Flowser is not yet installed on your system.")
100-
if !output.InstallPrompt() {
100+
installChoice := output.InstallPrompt()
101+
if installChoice == output.CancelInstall {
101102
return "", fmt.Errorf("user denied install")
102103
}
103104

105+
// if user says it already installed it we only ask for path and return it
106+
if installChoice == output.AlreadyInstalled {
107+
installPath = output.InstallPathPrompt(installPath)
108+
_ = settings.SetFlowserPath(installPath)
109+
return installPath, nil
110+
}
111+
104112
// we only allow custom paths on Windows since on MacOS apps needs to be installed inside Application folder
105113
if runtime.GOOS == settings.Windows {
106114
installPath = output.InstallPathPrompt(installPath)
@@ -111,7 +119,13 @@ func installFlowser(flowser *flowser.App, installPath string) (string, error) {
111119
logger.StartProgress(fmt.Sprintf("%s Installing Flowser, this may take few minutes, please wait ", output.TryEmoji()))
112120
defer logger.StopProgress()
113121

114-
err := flowser.Install(installPath)
122+
// create all folders if they don't exist, does nothing if they exist
123+
err := os.MkdirAll(installPath, os.ModePerm)
124+
if err != nil {
125+
return "", err
126+
}
127+
128+
err = flowser.Install(installPath)
115129
if err != nil {
116130
return "", fmt.Errorf("could not install Flowser: %w", err)
117131
}

pkg/flowkit/output/prompt.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -600,32 +600,39 @@ func WantToUseMainnetVersionPrompt() bool {
600600
return useMainnetVersion == "Yes"
601601
}
602602

603-
func InstallPrompt() bool {
604-
prompt := promptui.Prompt{
605-
Label: "Do you wish to install it",
606-
Default: "Y",
607-
IsConfirm: true,
608-
HideEntered: true,
603+
const CancelInstall = 1
604+
const AlreadyInstalled = 2
605+
606+
func InstallPrompt() int {
607+
prompt := promptui.Select{
608+
Label: "Do you wish to install it",
609+
Items: []string{"Yes", "No", "I've already installed it"},
609610
}
610-
selected, err := prompt.Run()
611+
index, _, err := prompt.Run()
611612
if err == promptui.ErrInterrupt {
612613
os.Exit(-1)
613614
}
614615

615-
return strings.ToLower(selected) == "y" || selected == ""
616+
return index
616617
}
617618

618619
func InstallPathPrompt(defaultPath string) string {
619620
prompt := promptui.Prompt{
620621
Label: "Install path",
621622
Default: defaultPath,
622623
Validate: func(s string) error {
623-
if s != "" {
624-
_, err := os.Stat(s)
625-
return err
624+
if _, err := os.Stat(s); err == nil {
625+
return nil
626626
}
627627

628-
return nil
628+
// Attempt to create it
629+
var d []byte
630+
if err := os.WriteFile(s, d, 0644); err == nil {
631+
os.Remove(s) // And delete it
632+
return nil
633+
}
634+
635+
return fmt.Errorf("path is invalid")
629636
},
630637
}
631638

0 commit comments

Comments
 (0)