-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creating registry from the cli, added the creation view of registry
Signed-off-by: amands98 <amandeepsm.in@gmail.com>
- Loading branch information
Showing
2 changed files
with
125 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package create | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/charmbracelet/huh" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type CreateView struct { | ||
Name string | ||
Type string | ||
Description string | ||
URL string | ||
Credential RegistryCredential | ||
Insecure bool | ||
} | ||
|
||
type RegistryCredential struct { | ||
AccessKey string `json:"access_key,omitempty"` | ||
Type string `json:"type,omitempty"` | ||
AccessSecret string `json:"access_secret,omitempty"` | ||
} | ||
|
||
func CreateRegistryView(createView *CreateView) { | ||
theme := huh.ThemeCharm() | ||
err := huh.NewForm( | ||
huh.NewGroup( | ||
huh.NewInput(). | ||
Title("Provider"). | ||
Value(&createView.Type). | ||
Validate(func(str string) error { | ||
if str == "" { | ||
return errors.New("provider cannot be empty") | ||
} | ||
return nil | ||
}), | ||
huh.NewInput(). | ||
Title("Name"). | ||
Value(&createView.Name). | ||
Validate(func(str string) error { | ||
if str == "" { | ||
return errors.New("name cannot be empty") | ||
} | ||
return nil | ||
}), | ||
huh.NewInput(). | ||
Title("Description"). | ||
Value(&createView.Description), | ||
huh.NewInput(). | ||
Title("URL"). | ||
Value(&createView.URL). | ||
Validate(func(str string) error { | ||
if str == "" { | ||
return errors.New("url cannot be empty") | ||
} | ||
return nil | ||
}), | ||
huh.NewInput(). | ||
Title("Access Key"). | ||
Value(&createView.Credential.AccessKey), | ||
huh.NewInput(). | ||
Title("Access Secret"). | ||
Value(&createView.Credential.AccessSecret), | ||
huh.NewConfirm(). | ||
Title("Verify Cert"). | ||
Value(&createView.Insecure). | ||
Affirmative("yes"). | ||
Negative("no"), | ||
), | ||
).WithTheme(theme).Run() | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |