Skip to content

Commit 828b019

Browse files
jonas-jonasory-bot
authored andcommitted
chore: generate elements locales from source and add CLI helpers
GitOrigin-RevId: bd97c592bbbeb786bc914699e2cdaa41e681d033
1 parent 029d8a3 commit 828b019

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

cmd/clidoc/main.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func init() {
8383
"NewErrorValidationVerificationStateFailure": text.NewErrorValidationVerificationStateFailure(),
8484
"NewErrorValidationVerificationCodeInvalidOrAlreadyUsed": text.NewErrorValidationVerificationCodeInvalidOrAlreadyUsed(),
8585
"NewErrorSystemGeneric": text.NewErrorSystemGeneric("{reason}"),
86+
"NewErrorSystemNoAuthenticationMethodsAvailable": text.NewErrorSystemNoAuthenticationMethodsAvailable(),
8687
"NewValidationErrorGeneric": text.NewValidationErrorGeneric("{reason}"),
8788
"NewValidationErrorRequired": text.NewValidationErrorRequired("{property}"),
8889
"NewErrorValidationMinLength": text.NewErrorValidationMinLength(5, 3),
@@ -194,6 +195,20 @@ func init() {
194195
}
195196

196197
func main() {
198+
if os.Args[1] == "elements" {
199+
path, err := filepath.Abs(os.Args[2])
200+
if err != nil {
201+
_, _ = fmt.Fprintf(os.Stderr, "Unable to determine absolute path for elements generation: %+v", err)
202+
os.Exit(1)
203+
}
204+
205+
if err := generateElements(path); err != nil {
206+
_, _ = fmt.Fprintf(os.Stderr, "Unable to generate locales for elements: %+v", err)
207+
os.Exit(1)
208+
}
209+
return
210+
}
211+
197212
if err := clidoc.Generate(cmd.NewRootCmd(nil, nil), []string{filepath.Join(os.Args[2], "cli")}); err != nil {
198213
_, _ = fmt.Fprintf(os.Stderr, "Unable to generate CLI docs: %+v", err)
199214
os.Exit(1)
@@ -382,3 +397,20 @@ func validateAllMessages(path string) error {
382397

383398
return nil
384399
}
400+
401+
func generateElements(messageFilePath string) error {
402+
// If the file at messageFilePath does not exist, create it
403+
f, err := os.OpenFile(messageFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) // #nosec
404+
if err != nil {
405+
return errors.Wrapf(err, "unable to open or create message file at %s", messageFilePath)
406+
}
407+
if err := f.Close(); err != nil {
408+
return errors.Wrapf(err, "unable to close message file at %s", messageFilePath)
409+
}
410+
411+
sortedMessages := sortMessages()
412+
if err := writeMessagesJson(messageFilePath, sortedMessages); err != nil {
413+
return errors.Wrapf(err, "unable to write messages json to %s", messageFilePath)
414+
}
415+
return nil
416+
}

text/id.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ const (
211211
)
212212

213213
const (
214-
ErrorSystem ID = 5000000 + iota
215-
ErrorSystemGeneric
214+
ErrorSystem ID = 5000000 + iota // 5000000
215+
ErrorSystemGeneric // 5000001
216+
ErrorSystemNoAuthenticationMethodsAvailable // 5000002
216217
)

text/id_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func TestIDs(t *testing.T) {
6363
assert.Equal(t, 4070001, int(ErrorValidationVerificationTokenInvalidOrAlreadyUsed))
6464

6565
assert.Equal(t, 5000000, int(ErrorSystem))
66+
assert.Equal(t, 5000001, int(ErrorSystemGeneric))
67+
assert.Equal(t, 5000002, int(ErrorSystemNoAuthenticationMethodsAvailable))
6668

6769
assert.Equal(t, 4060006, int(ErrorValidationRecoveryCodeInvalidOrAlreadyUsed))
6870
assert.Equal(t, 4070006, int(ErrorValidationVerificationCodeInvalidOrAlreadyUsed))

text/message_system.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ func NewErrorSystemGeneric(reason string) *Message {
1414
}
1515
}
1616

17+
func NewErrorSystemNoAuthenticationMethodsAvailable() *Message {
18+
return &Message{
19+
ID: ErrorSystemNoAuthenticationMethodsAvailable,
20+
Text: "No authentication methods are available. Please contact the system administrator.",
21+
Type: Error,
22+
}
23+
}
24+
1725
func NewCaptchaContainerMessage() *Message {
1826
return &Message{
1927
ID: InfoNodeLabelCaptcha,

0 commit comments

Comments
 (0)