Skip to content

Commit

Permalink
more tuning for validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jippi committed Feb 10, 2024
1 parent 980bdfa commit c73f3e0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
40 changes: 24 additions & 16 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
# app
################################################################################

# The name/title for your site
# @see https://docs.pixelfed.org/technical-documentation/config/#app_name-1
# @dottie/validate required
APP_NAME="Pixelfed Prod"
# @dottie/validate required,ne=My Pixelfed Site
APP_NAME="My Pixelfed Site"

# Application domains used for routing.
# Application domain used for routing. (e.g., pixelfed.org)
#
# @see https://docs.pixelfed.org/technical-documentation/config/#app_domain
# @dottie/validate required,fqdn
APP_DOMAIN="__CHANGE_ME__"
# @dottie/validate required,ne=example.com,fqdn
APP_DOMAIN="example.com"

# This URL is used by the console to properly generate URLs when using the Artisan command line tool.
# You should set this to the root of your application so that it is used when running Artisan tasks.
Expand Down Expand Up @@ -208,10 +209,12 @@ APP_TIMEZONE="UTC"
# @dottie/validate required,boolean
#INSTANCE_PUBLIC_HASHTAGS="false"

# The public e-mail address people can use to contact you by
#
# @default ""
# @see https://docs.pixelfed.org/technical-documentation/config/#instance_contact_email
# @dottie/validate required,email
INSTANCE_CONTACT_EMAIL="admin@${APP_DOMAIN}"
# @dottie/validate required,ne=__CHANGE_ME__,email
INSTANCE_CONTACT_EMAIL="__CHANGE_ME__"

# @default "false"
# @see https://docs.pixelfed.org/technical-documentation/config/#instance_public_local_timeline
Expand All @@ -237,7 +240,7 @@ INSTANCE_CONTACT_EMAIL="admin@${APP_DOMAIN}"
# @default false
# @see https://docs.pixelfed.org/technical-documentation/config/#media_exif_database
# @dottie/validate required,boolean
MEDIA_EXIF_DATABASE="true"
#MEDIA_EXIF_DATABASE="false"

# Pixelfed supports GD or ImageMagick to process images.
#
Expand Down Expand Up @@ -357,9 +360,12 @@ DB_HOST="db"
# @dottie/validate required
DB_USERNAME="pixelfed"

# The password to your database. Please make it secure.
# Use a site like https://pwgen.io/ to generate it
#
# @see https://docs.pixelfed.org/technical-documentation/config/#db_password
# @dottie/validate required
DB_PASSWORD=
# @dottie/validate required,ne=__CHANGE_ME__
DB_PASSWORD="__CHANGE_ME__"

# @see https://docs.pixelfed.org/technical-documentation/config/#db_database
# @dottie/validate required
Expand Down Expand Up @@ -416,19 +422,21 @@ DB_APPLY_NEW_MIGRATIONS_AUTOMATICALLY="false"
# @dottie/validate required_with=MAIL_DRIVER,number
#MAIL_PORT="587"

# You may wish for all e-mails sent by your application to be sent from the same address.
#
# Here, you may specify a name and address that is used globally for all e-mails that are sent by your application.
#
# @default "hello@example.com"
# You may wish for all e-mails sent by your application to be sent from the same address.
#
# @default "bot@example.com"
# @see https://docs.pixelfed.org/technical-documentation/config/#mail_from_address
# @dottie/validate required_with=MAIL_DRIVER,email
MAIL_FROM_ADDRESS="hello@${APP_DOMAIN}"
# @dottie/validate required_with=MAIL_DRIVER,email,ne=__CHANGE_ME__
#MAIL_FROM_ADDRESS="__CHANGE_ME__"

# The 'name' you send e-mail from
#
# @default "Example"
# @see https://docs.pixelfed.org/technical-documentation/config/#mail_from_name
# @dottie/validate required_with=MAIL_DRIVER
MAIL_FROM_NAME="Pixelfed @ ${APP_DOMAIN}"
#MAIL_FROM_NAME="${APP_NAME}"

# If your SMTP server requires a username for authentication, you should set it here.
#
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func main() {
root.AddCommand(validate.Command())
root.AddCommand(value.Command)

root.PersistentFlags().String("file", ".env", "Load this file")
root.PersistentFlags().StringP("file", "f", ".env", "Load this file")

if c, err := root.ExecuteC(); err != nil {
tui.Theme.Danger.StderrPrinter(tui.WithEmphasis(true)).Println(c.ErrPrefix(), err.Error())
Expand Down
2 changes: 1 addition & 1 deletion pkg/ast/assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (a *Assignment) Documentation(withoutPrefix bool) string {
val := comment.Value

if withoutPrefix {
val = strings.TrimPrefix(val, "# ")
val = strings.TrimPrefix(val, "#")
}

buff.WriteString(val)
Expand Down
11 changes: 10 additions & 1 deletion pkg/validation/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ func Explain(env *ast.Document, keyErr ValidationError, fix bool) {
AskToSetValue(env, keyErr.Assignment)
}

case "ne":
light.Println("(ne) The value must NOT be equal to [" + bold.Sprintf(keyErr.Assignment.Interpolated) + "], please change it")

if fix {
AskToSetValue(env, keyErr.Assignment)
}

case "http_url":
light.Println("(http_url) The value [" + bold.Sprintf(keyErr.Assignment.Interpolated) + "] is not a valid HTTP URL (e.g., 'https://example.com').")

Expand Down Expand Up @@ -129,10 +136,12 @@ func AskToCreateDirectory(path string) {
}

func AskToSetValue(env *ast.Document, assignment *ast.Assignment) {
fmt.Println()

var value string

err := huh.NewInput().
Title("Please provide input").
Title("Please provide value for " + assignment.Name).
Description(strings.TrimSpace(assignment.Documentation(true))).
Validate(func(s string) error {
return validator.New().Var(s, assignment.ValidationRules())
Expand Down

0 comments on commit c73f3e0

Please sign in to comment.