Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
build secman main file
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Mar 10, 2022
1 parent cc218bf commit d5fea08
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package main

import (
"os"
"fmt"
"errors"
"runtime"

"github.com/mgutz/ansi"
"github.com/spf13/cobra"
"github.com/scmn-dev/secman/tools"
"github.com/scmn-dev/secman/cmd/secman"
"github.com/scmn-dev/secman/cmd/factory"
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/scmn-dev/secman/internal/checker"
surveyCore "github.com/AlecAivazis/survey/v2/core"
)

var (
version string
buildDate string
)

type exitCode int

const (
exitOK exitCode = 0
exitError exitCode = 1
exitCancel exitCode = 2
)

func main() {
code := mainRun()
os.Exit(int(code))
}

func mainRun() exitCode {
runtime.LockOSThread()

cmdFactory := factory.New()
hasDebug := os.Getenv("DEBUG") != ""
stderr := cmdFactory.IOStreams.ErrOut

if !cmdFactory.IOStreams.ColorEnabled() {
surveyCore.DisableColor = true
} else {
surveyCore.TemplateFuncsWithColor["color"] = func(style string) string {
switch style {
case "white":
if cmdFactory.IOStreams.ColorSupport256() {
return fmt.Sprintf("\x1b[%d;5;%dm", 38, 242)
}

return ansi.ColorCode("default")

default:
return ansi.ColorCode(style)
}
}
}

if len(os.Args) > 1 && os.Args[1] != "" {
cobra.MousetrapHelpText = ""
}

RootCmd := secman.Execute(cmdFactory, version, buildDate)

if cmd, err := RootCmd.ExecuteC(); err != nil {
if err == tools.SilentError {
return exitError
} else if tools.IsUserCancellation(err) {
if errors.Is(err, terminal.InterruptErr) {
fmt.Fprint(stderr, "\n")
}

return exitCancel
}

tools.PrintError(stderr, err, cmd, hasDebug)

return exitError
}

if secman.HasFailed() {
return exitError
}

checker.Check(version)

return exitOK
}

0 comments on commit d5fea08

Please sign in to comment.