MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / preRun

Function preRun

cmd/ttn-lw-cli/commands/root.go:121–270  ·  view source on GitHub ↗
(tasks ...func() error)

Source from the content-addressed store, hash-verified

119func runNoop(cmd *cobra.Command, args []string) error { return nil }
120
121func preRun(tasks ...func() error) func(cmd *cobra.Command, args []string) error {
122 return func(cmd *cobra.Command, args []string) error {
123 // read in config from file
124 err := mgr.ReadInConfig()
125 if err != nil {
126 return err
127 }
128
129 // unmarshal config
130 if err = mgr.Unmarshal(config); err != nil {
131 return err
132 }
133
134 // enable configured experimental features
135 experimental.EnableFeatures(config.Experimental.Features...)
136
137 // create input decoder on Stdin
138 if rd, ok := cmdio.BufferedPipe(os.Stdin); ok {
139 inputDecoder, err = getInputDecoder(rd)
140 if err != nil {
141 return err
142 }
143 }
144
145 // get cache
146 cache, err = util.GetAuthCache()
147 if err != nil {
148 return err
149 }
150 cache = cache.ForID(config.CredentialsID)
151
152 // create logger
153 logger, err = shared.InitializeLogger(&config.Log)
154 if err != nil {
155 return err
156 }
157
158 ctx = log.NewContext(ctx, logger)
159
160 // Start the version check in background.
161 // The result is waited in the post run.
162 versionUpdate = make(chan *pkgversion.Update)
163 if config.SkipVersionCheck {
164 close(versionUpdate)
165 } else {
166 go func(ctx context.Context) {
167 defer close(versionUpdate)
168 update, err := pkgversion.CheckUpdate(ctx)
169 if err != nil {
170 log.FromContext(ctx).WithError(err).Warn("Failed to check version update")
171 } else if update != nil {
172 versionUpdate <- update
173 } else {
174 log.FromContext(ctx).Debug("No new version available")
175 }
176 }(ctx)
177 }
178

Callers 10

end_devices.goFile · 0.85
users.goFile · 0.85
users_access.goFile · 0.85
login.goFile · 0.85
root.goFile · 0.85
lorawan.goFile · 0.85
initFunction · 0.85
use.goFile · 0.85
gateways.goFile · 0.85

Calls 15

EnableFeaturesFunction · 0.92
GetAuthCacheFunction · 0.92
InitializeLoggerFunction · 0.92
NewContextFunction · 0.92
FromContextFunction · 0.92
SetLoggerFunction · 0.92
SetInsecureFunction · 0.92
SetDumpRequestsFunction · 0.92
SetRetryMaxFunction · 0.92
SetRetryDefaultTimeoutFunction · 0.92
SetRetryEnableMetadataFunction · 0.92
SetRetryJitterFunction · 0.92

Tested by

no test coverage detected