Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for registering/ retrieving env variables using goflags #129

Open
tarunKoyalwar opened this issue Aug 9, 2023 · 0 comments
Open
Assignees
Labels
Type: Enhancement Most issues will probably ask for additions or changes.

Comments

@tarunKoyalwar
Copy link
Member

tarunKoyalwar commented Aug 9, 2023

Proposed Changes

  • we use env variables as switches for many reasons some of them include

    • feasibility from implementation persepective
    • feature/switch does not need a flag (at least yet)
    • making library/SDK related switches available in downstream tools (ex: DEBUG=true for errorutil will print stacktrace)
  • when env are registered/consumed from this implementation . all envs are available in help section of that tool (ex: nuclei -h envs) or something similar

  • while goflags is primary developed for tools and not SDKs . this feature should be possible to be used in libraries without the need of making it a tool (see implementation) . this way all inherited envs are available in downstream tools

Implementation

  • unlike flags this feature should be registred through global functions instead of methods from flagSet Type/Object etc (see ^ 3)

  • below is example of using this in a library/tool

// something.go

var tlsVerify bool

// logic &
// code
// of 
// library


func init() {
   goflags.BoolEnv(&tlsVerify,"TLS_VERIFY","false","Enable/Disable TLS certificate verification")
}

since go executes in following behaviour global variables -> init() -> main() -------> there shouldn't be any trouble with logic

expected output is something similar to this

$ nuclei -h env

   TLS_VERIFY       (default: false)         Enable/Disable TLS Certificate Verification 
   DEBUG            (default: false)         Enable/Disable Printing StackTrace of errors
@tarunKoyalwar tarunKoyalwar self-assigned this Aug 9, 2023
@ehsandeep ehsandeep added the Type: Enhancement Most issues will probably ask for additions or changes. label Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Most issues will probably ask for additions or changes.
Projects
None yet
Development

No branches or pull requests

2 participants