• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

snivilised / arcadia / 12234394440

09 Dec 2024 11:10AM UTC coverage: 76.053%. Remained the same
12234394440

Pull #304

github

web-flow
chore(deps): bump golang.org/x/text from 0.20.0 to 0.21.0

Bumps [golang.org/x/text](https://github.com/golang/text) from 0.20.0 to 0.21.0.
- [Release notes](https://github.com/golang/text/releases)
- [Commits](https://github.com/golang/text/compare/v0.20.0...v0.21.0)

---
updated-dependencies:
- dependency-name: golang.org/x/text
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #304: chore(deps): bump golang.org/x/text from 0.20.0 to 0.21.0

289 of 380 relevant lines covered (76.05%)

1.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.12
/src/app/command/bootstrap.go
1
package command
2

3
import (
4
        "fmt"
5
        "os"
6

7
        "github.com/cubiest/jibberjabber"
8
        "github.com/samber/lo"
9
        "github.com/snivilised/arcadia/src/locale"
10
        "github.com/snivilised/cobrass/src/assistant"
11
        "github.com/snivilised/cobrass/src/assistant/configuration"
12
        ci18n "github.com/snivilised/cobrass/src/assistant/locale"
13
        "github.com/snivilised/li18ngo"
14
        "github.com/spf13/cobra"
15
        "github.com/spf13/pflag"
16
        "github.com/spf13/viper"
17
        "golang.org/x/text/language"
18
)
19

20
type LocaleDetector interface {
21
        Scan() language.Tag
22
}
23

24
// Jabber is a LocaleDetector implemented using jibberjabber.
25
type Jabber struct {
26
}
27

28
// Scan returns the detected language tag.
29
func (j *Jabber) Scan() language.Tag {
×
30
        lang, _ := jibberjabber.DetectIETF()
×
31
        return language.MustParse(lang)
×
32
}
×
33

34
type ConfigInfo struct {
35
        Name       string
36
        ConfigType string
37
        ConfigPath string
38
        Viper      configuration.ViperConfig
39
}
40

41
type ConfigureOptions struct {
42
        Detector LocaleDetector
43
        Config   ConfigInfo
44
}
45

46
type ConfigureOptionFn func(*ConfigureOptions)
47

48
// Bootstrap represents construct that performs start up of the cli
49
// without resorting to the use of Go's init() mechanism and minimal
50
// use of package global variables.
51
type Bootstrap struct {
52
        container *assistant.CobraContainer
53
        options   ConfigureOptions
54
}
55

56
func (b *Bootstrap) prepare() {
2✔
57
        home, err := os.UserHomeDir()
2✔
58
        cobra.CheckErr(err)
2✔
59

2✔
60
        b.options = ConfigureOptions{
2✔
61
                Detector: &Jabber{},
2✔
62
                Config: ConfigInfo{
2✔
63
                        Name:       ApplicationName,
2✔
64
                        ConfigType: "yaml",
2✔
65
                        ConfigPath: home,
2✔
66
                        Viper:      &configuration.GlobalViperConfig{},
2✔
67
                },
2✔
68
        }
2✔
69
}
2✔
70

71
// Root builds the command tree and returns the root command, ready
72
// to be executed.
73
func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {
2✔
74
        b.prepare()
2✔
75

2✔
76
        for _, fo := range options {
4✔
77
                fo(&b.options)
2✔
78
        }
2✔
79

80
        b.configure()
2✔
81

2✔
82
        // all these string literals here should be made translate-able
2✔
83
        //
2✔
84

2✔
85
        b.container = assistant.NewCobraContainer(
2✔
86
                &cobra.Command{
2✔
87
                        Use:     "main",
2✔
88
                        Short:   li18ngo.Text(locale.RootCmdShortDescTemplData{}),
2✔
89
                        Long:    li18ngo.Text(locale.RootCmdLongDescTemplData{}),
2✔
90
                        Version: fmt.Sprintf("'%v'", Version),
2✔
91
                        // Uncomment the following line if your bare application
2✔
92
                        // has an action associated with it:
2✔
93
                        // Run: func(cmd *cobra.Command, args []string) { },
2✔
94
                },
2✔
95
        )
2✔
96

2✔
97
        b.buildRootCommand(b.container)
2✔
98
        b.buildWidgetCommand(b.container)
2✔
99

2✔
100
        return b.container.Root()
2✔
101
}
102

103
func (b *Bootstrap) configure() {
2✔
104
        vc := b.options.Config.Viper
2✔
105
        ci := b.options.Config
2✔
106

2✔
107
        vc.SetConfigName(ci.Name)
2✔
108
        vc.SetConfigType(ci.ConfigType)
2✔
109
        vc.AddConfigPath(ci.ConfigPath)
2✔
110
        vc.AutomaticEnv()
2✔
111

2✔
112
        err := vc.ReadInConfig()
2✔
113

2✔
114
        handleLangSetting()
2✔
115

2✔
116
        if err != nil {
4✔
117
                msg := li18ngo.Text(locale.UsingConfigFileTemplData{
2✔
118
                        ConfigFileName: viper.ConfigFileUsed(),
2✔
119
                })
2✔
120
                fmt.Fprintln(os.Stderr, msg)
2✔
121
        }
2✔
122
}
123

124
func handleLangSetting() {
2✔
125
        tag := lo.TernaryF(viper.InConfig("lang"),
2✔
126
                func() language.Tag {
2✔
127
                        lang := viper.GetString("lang")
×
128
                        parsedTag, err := language.Parse(lang)
×
129

×
130
                        if err != nil {
×
131
                                fmt.Println(err)
×
132
                                os.Exit(1)
×
133
                        }
×
134

135
                        return parsedTag
×
136
                },
137
                func() language.Tag {
2✔
138
                        return li18ngo.DefaultLanguage
2✔
139
                },
2✔
140
        )
141

142
        err := li18ngo.Use(func(uo *li18ngo.UseOptions) {
4✔
143
                uo.Tag = tag
2✔
144
                uo.From = li18ngo.LoadFrom{
2✔
145
                        Sources: li18ngo.TranslationFiles{
2✔
146
                                SourceID: li18ngo.TranslationSource{Name: ApplicationName},
2✔
147

2✔
148
                                // By adding in the source for cobrass, we relieve the client from having
2✔
149
                                // to do this. After-all, it should be taken as read that since any
2✔
150
                                // instantiation of arcadia (ie a project using this template) is by
2✔
151
                                // necessity dependent on cobrass, it's source should be loaded so that a
2✔
152
                                // localizer can be created for it.
2✔
153
                                //
2✔
154
                                // The client app has to make sure that when their app is deployed,
2✔
155
                                // the translations file(s) for cobrass are named as 'cobrass', as you
2✔
156
                                // can see below, that is the name assigned to the app name of the
2✔
157
                                // source.
2✔
158
                                //
2✔
159
                                ci18n.CobrassSourceID: li18ngo.TranslationSource{Name: "cobrass"},
2✔
160
                        },
2✔
161
                }
2✔
162
        })
2✔
163

164
        if err != nil {
2✔
165
                fmt.Println(err)
×
166
                os.Exit(1)
×
167
        }
×
168
}
169

170
func (b *Bootstrap) buildRootCommand(container *assistant.CobraContainer) {
2✔
171
        // Here you will define your flags and configuration settings.
2✔
172
        // Cobra supports persistent flags, which, if defined here,
2✔
173
        // will be global for your application.
2✔
174
        //
2✔
175
        root := container.Root()
2✔
176
        paramSet := assistant.NewParamSet[RootParameterSet](root)
2✔
177

2✔
178
        paramSet.BindValidatedString(&assistant.FlagInfo{
2✔
179
                Name:               "lang",
2✔
180
                Usage:              li18ngo.Text(locale.RootCmdLangUsageTemplData{}),
2✔
181
                Default:            li18ngo.DefaultLanguage.String(),
2✔
182
                AlternativeFlagSet: root.PersistentFlags(),
2✔
183
        }, &paramSet.Native.Language, func(value string, _ *pflag.Flag) error {
2✔
184
                _, err := language.Parse(value)
×
185
                return err
×
186
        })
×
187

188
        container.MustRegisterParamSet(RootPsName, paramSet)
2✔
189
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc