-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
56 lines (51 loc) · 1.39 KB
/
main.go
File metadata and controls
56 lines (51 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright Louis Royer and the NextMN contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT
package main
import (
"context"
"os"
"os/signal"
"runtime/debug"
"syscall"
"time"
"github.com/nextmn/logrus-formatter/logger"
"github.com/nextmn/docker-setup/internal/app"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v3"
)
func main() {
logger.Init("docker-setup")
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer cancel()
version := "Unknown version"
if info, ok := debug.ReadBuildInfo(); ok {
version = info.Main.Version
}
app := &cli.Command{
Name: "docker-setup",
Usage: "Docker-setup - Configure a container for networking",
EnableShellCompletion: true,
Authors: []any{
"Louis Royer",
},
Version: version,
Action: func(ctx context.Context, cmd *cli.Command) error {
conf := app.NewConf()
conf.RunInitHooks(ctx)
if !conf.Oneshot() {
defer func() {
shCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 1*time.Second)
defer cancel()
conf.RunExitHooks(shCtx)
}()
<-ctx.Done()
}
return nil
},
}
if err := app.Run(ctx, os.Args); err != nil {
logrus.WithError(err).Fatal("Fatal error while running the application")
}
}