apiEndpoint validation tweaks (#260)

This commit is contained in:
Michael Quigley 2023-03-10 16:33:58 -05:00
parent 1c39fd5f3e
commit 6e17f4df3a
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 6 additions and 6 deletions

2
.gitignore vendored
View File

@ -4,6 +4,7 @@
*.db *.db
automated-release-build automated-release-build
etc/dev.yml etc/dev.yml
etc/dev-metrics.yml
# Dependencies # Dependencies
/node_modules/ /node_modules/
@ -28,3 +29,4 @@ npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
.obsidian

View File

@ -44,14 +44,12 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) {
if zrd.Cfg == nil { if zrd.Cfg == nil {
zrd.Cfg = &zrokdir.Config{} zrd.Cfg = &zrokdir.Config{}
} }
ok, err := isValidUrl(value) ok, err := isFullyValidUrl(value)
if err != nil { if err != nil {
fmt.Println("unable to validate api endpoint") tui.Error("unable to validate api endpoint", err)
os.Exit(1)
} }
if !ok { if !ok {
fmt.Println("invalid apiEndpoint, please make sure scheme and host is provided") tui.Error("invalid apiEndpoint; please make sure URL starts with http:// or https://", nil)
os.Exit(1)
} }
zrd.Cfg.ApiEndpoint = value zrd.Cfg.ApiEndpoint = value
modified = true modified = true
@ -74,7 +72,7 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) {
} }
} }
func isValidUrl(rawUrl string) (bool, error) { func isFullyValidUrl(rawUrl string) (bool, error) {
u, err := url.Parse(rawUrl) u, err := url.Parse(rawUrl)
if err != nil { if err != nil {
return false, err return false, err