add inbound option and custom flags

This commit is contained in:
Hiddify
2024-05-29 18:47:04 +02:00
parent ed423fec45
commit 0bbd581277
7 changed files with 54 additions and 13 deletions

View File

@@ -14,6 +14,7 @@ import (
"github.com/spf13/cobra"
)
var defaultConfigs config.ConfigOptions
var commandBuildOutputPath string
var commandBuild = &cobra.Command{
@@ -46,8 +47,10 @@ var commandCheck = &cobra.Command{
func init() {
commandBuild.Flags().StringVarP(&commandBuildOutputPath, "output", "o", "", "write result to file path instead of stdout")
addHConfigFlags(commandBuild)
mainCommand.AddCommand(commandBuild)
mainCommand.AddCommand(commandCheck)
}
func build(path string, optionsPath string) error {
@@ -62,7 +65,8 @@ func build(path string, optionsPath string) error {
if err != nil {
return err
}
configOptions := config.DefaultConfigOptions()
configOptions := &defaultConfigs //config.DefaultConfigOptions()
if optionsPath != "" {
configOptions, err = readConfigOptionsAt(optionsPath)
if err != nil {
@@ -138,3 +142,24 @@ func readConfigOptionsAt(path string) (*config.ConfigOptions, error) {
return &options, nil
}
func addHConfigFlags(commandRun *cobra.Command) {
commandRun.Flags().BoolVar(&defaultConfigs.EnableFullConfig, "full-config", false, "allows including tags other than output")
commandRun.Flags().StringVar(&defaultConfigs.LogLevel, "log", "warn", "log level")
commandRun.Flags().BoolVar(&defaultConfigs.InboundOptions.EnableTun, "tun", false, "Enable Tun")
commandRun.Flags().BoolVar(&defaultConfigs.InboundOptions.EnableTunService, "tun-service", false, "Enable Tun Service")
commandRun.Flags().BoolVar(&defaultConfigs.InboundOptions.SetSystemProxy, "system-proxy", false, "Enable System Proxy")
commandRun.Flags().Uint16Var(&defaultConfigs.InboundOptions.MixedPort, "in-proxy-port", 2334, "Input Mixed Port")
commandRun.Flags().BoolVar(&defaultConfigs.TLSTricks.EnableFragment, "fragment", false, "Enable Fragment")
commandRun.Flags().StringVar(&defaultConfigs.TLSTricks.FragmentSize, "fragment-size", "2-4", "FragmentSize")
commandRun.Flags().StringVar(&defaultConfigs.TLSTricks.FragmentSleep, "fragment-sleep", "2-4", "FragmentSleep")
commandRun.Flags().BoolVar(&defaultConfigs.TLSTricks.EnablePadding, "padding", false, "Enable Padding")
commandRun.Flags().StringVar(&defaultConfigs.TLSTricks.PaddingSize, "padding-size", "1300-1400", "PaddingSize")
commandRun.Flags().BoolVar(&defaultConfigs.TLSTricks.MixedSNICase, "mixed-sni-case", false, "MixedSNICase")
commandRun.Flags().StringVar(&defaultConfigs.RemoteDnsAddress, "dns-remote", "1.1.1.1", "RemoteDNS (1.1.1.1, https://1.1.1.1/dns-query)")
commandRun.Flags().StringVar(&defaultConfigs.DirectDnsAddress, "dns-direct", "1.1.1.1", "DirectDNS (1.1.1.1, https://1.1.1.1/dns-query)")
}