bepass-org / oblivion

Unofficial warp client for android
3.43k stars 464 forks source link

Refactor and Improve Command-line Flag Parsing #3

Closed comm4nd3rx closed 4 months ago

comm4nd3rx commented 4 months ago

Hey there,

I think the command-line flag parsing section to be a bit complex. I've made some improvements to make it more efficient. Before sending a pull request, I wanted to discuss these changes with you and ensure they align with your vision for the project.

Here's the modified code:

    fs := flag.NewFlagSet("warp-plus-go", flag.ExitOnError)

    verbose = fs.Bool("v", false, "Enable verbose logging.")
    bindAddress = fs.String("b", "127.0.0.1:8086", "Set the SOCKS bind address.")
    endpoint = fs.String("e", "notset", "Specify the Warp endpoint IP.")
    license = fs.String("k", "notset", "Your Warp license key.")
    country = fs.String("country", "", "ISO 3166-1 alpha-2 country code for Psiphon.")
    psiphonEnabled = fs.Bool("cfon", false, "Enable Psiphon over Warp.")
    gool = fs.Bool("gool", false, "Enable Warp in Warp.")
    scan = fs.Bool("scan", false, "Enable Warp scanner (experimental).")

    flag.Usage = func() {
        fmt.Printf("Usage: %s [-v] [-b addr:port] [-e warp-ip] [-k license-key] [-country country-code] [-cfon] [-gool] [-scan]\n", fs.Name())
        fmt.Println("Options:")
        fs.PrintDefaults()
    }

    err := fs.Parse(os.Args[1:])
    if err != nil {
        log.Fatalf("Failed to parse flags: %v", err)
    }

    if err := validateFlags(); err != nil {
        log.Fatalf("Validation error: %v", err)
    }

func validateFlags() error {
    if *psiphonEnabled && *country == "" {
        return fmt.Errorf("if Psiphon is enabled, country code must be provided")
    }

    // Other validations ... ( like a map for country codes )

    return nil
}

I've also added a usage message to guide users on how to use the application effectively.

Usage: warp-plus-go [-v] [-b addr:port] [-e warp-ip] [-k license-key] [-country country-code] [-cfon] [-gool] [-scan]
Options:
  -v            Enable verbose logging.
  -b            Set the SOCKS bind address.
  -e            Specify the Warp endpoint IP.
  -k            Your Warp license key.
  -country      ISO 3166-1 alpha-2 country code for Psiphon.
  -cfon         Enable Psiphon over Warp.
  -gool         Enable Warp in Warp.
  -scan         Enable Warp scanner (experimental).

would appreciate your feedback on these changes. If you find them suitable, I'll be happy to create a pull request for it

uoosef commented 4 months ago

hi, ok here we dont actually parse os args, because native part is in aar format we can directly call go functions from java instead of running it as an executable, i now a better solution is to make an struct of options instead of parsing them from string, but because im lazy i assemble an string in java and send it to aar then it parses the flags from that string not os args., thecore repo is here if you want to contribute https://github.com/bepass-org/wireguard-go

comm4nd3rx commented 4 months ago

Oki, thanks for the clarifications. I'll be sending a pull request to the core repository.