2023-12-02 19:52:16 +03:30
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
"time"
|
|
|
|
|
|
2024-01-21 10:56:55 +00:00
|
|
|
"context"
|
|
|
|
|
|
2023-12-02 19:52:16 +03:30
|
|
|
"github.com/sagernet/sing-box/log"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
workingDir string
|
|
|
|
|
disableColor bool
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var mainCommand = &cobra.Command{
|
|
|
|
|
Use: "hiddify-next",
|
|
|
|
|
PersistentPreRun: preRun,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
2024-01-28 17:38:37 +03:30
|
|
|
mainCommand.AddCommand(commandService)
|
2024-01-28 19:08:51 +03:30
|
|
|
mainCommand.AddCommand(commandGenerateCertification)
|
2024-01-28 17:38:37 +03:30
|
|
|
|
2023-12-02 19:52:16 +03:30
|
|
|
mainCommand.PersistentFlags().StringVarP(&workingDir, "directory", "D", "", "set working directory")
|
|
|
|
|
mainCommand.PersistentFlags().BoolVarP(&disableColor, "disable-color", "", false, "disable color output")
|
2024-01-28 17:38:37 +03:30
|
|
|
|
2023-12-02 19:52:16 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
if err := mainCommand.Execute(); err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func preRun(cmd *cobra.Command, args []string) {
|
|
|
|
|
if disableColor {
|
2024-01-21 10:56:55 +00:00
|
|
|
log.SetStdLogger(log.NewDefaultFactory(context.Background(), log.Formatter{BaseTime: time.Now(), DisableColors: true}, os.Stderr, "", nil, false).Logger())
|
2023-12-02 19:52:16 +03:30
|
|
|
}
|
|
|
|
|
if workingDir != "" {
|
|
|
|
|
_, err := os.Stat(workingDir)
|
|
|
|
|
if err != nil {
|
2024-01-29 21:55:01 +01:00
|
|
|
os.MkdirAll(workingDir, 0o0644)
|
2023-12-02 19:52:16 +03:30
|
|
|
}
|
|
|
|
|
if err := os.Chdir(workingDir); err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|