skipBootstrap eagerly checks if the app should skip the bootstrap process: - already bootstrapped - is unknown command - is the default help command - is the default version command https://github.com/pocketbase/pocketbase/issues/404 https://github.com/pocketbase/pocketbase/discussions/1267
()
| 257 | // https://github.com/pocketbase/pocketbase/issues/404 |
| 258 | // https://github.com/pocketbase/pocketbase/discussions/1267 |
| 259 | func (pb *PocketBase) skipBootstrap() bool { |
| 260 | flags := []string{ |
| 261 | "-h", |
| 262 | "--help", |
| 263 | "-v", |
| 264 | "--version", |
| 265 | } |
| 266 | |
| 267 | if pb.IsBootstrapped() { |
| 268 | return true // already bootstrapped |
| 269 | } |
| 270 | |
| 271 | cmd, _, err := pb.RootCmd.Find(os.Args[1:]) |
| 272 | if err != nil { |
| 273 | return true // unknown command |
| 274 | } |
| 275 | |
| 276 | for _, arg := range os.Args { |
| 277 | if !list.ExistInSlice(arg, flags) { |
| 278 | continue |
| 279 | } |
| 280 | |
| 281 | // ensure that there is no user defined flag with the same name/shorthand |
| 282 | trimmed := strings.TrimLeft(arg, "-") |
| 283 | if len(trimmed) > 1 && cmd.Flags().Lookup(trimmed) == nil { |
| 284 | return true |
| 285 | } |
| 286 | if len(trimmed) == 1 && cmd.Flags().ShorthandLookup(trimmed) == nil { |
| 287 | return true |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | return false |
| 292 | } |
| 293 | |
| 294 | // inspectRuntime tries to find the base executable directory and how it was run. |
| 295 | // |