diff --git a/addon.go b/addon.go index 46faf6c..cff92d2 100644 --- a/addon.go +++ b/addon.go @@ -2,7 +2,6 @@ package stremio import ( "errors" - "flag" "fmt" netpprof "net/http/pprof" "os" @@ -56,11 +55,6 @@ type Addon struct { userDataType reflect.Type } -func init() { - // We need to overwrite the usage of the default FlagSet to hide the flags defined by Fiber - flag.CommandLine.Usage = usage -} - // NewAddon creates a new Addon object that can be started with Run(). // A proper manifest must be supplied, but manifestCallback and all but one handler can be nil in case you only want to handle specific requests and opts can be the zero value of Options. func NewAddon(manifest Manifest, catalogHandlers map[string]CatalogHandler, streamHandlers map[string]StreamHandler, opts Options) (*Addon, error) { diff --git a/flags.go b/flags.go deleted file mode 100644 index 60a7016..0000000 --- a/flags.go +++ /dev/null @@ -1,81 +0,0 @@ -package stremio - -import ( - "flag" - "fmt" - "os" - "reflect" - "strings" -) - -// -- string Value -// This code is copied from the stdlib. -type stringValue string - -// This code is copied from the stdlib. -func (s *stringValue) Set(val string) error { - *s = stringValue(val) - return nil -} - -// This code is copied from the stdlib. -func (s *stringValue) Get() interface{} { return string(*s) } - -// This code is copied from the stdlib. -func (s *stringValue) String() string { return string(*s) } - -// usage prints the usage of the flags an SDK user sets. -// It skips printing Fiber's `-prefork` and `-prefork-child`, that it defines as of Fiber v1.12.4. -// This code is based on the stdlib with the only change to skip those two flags. -func usage() { - fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0]) - flag.CommandLine.VisitAll(func(f *flag.Flag) { - // Skip printing usage info for Fiber's flags - if f.Name == "prefork" || f.Name == "prefork-child" { - return - } - - s := fmt.Sprintf(" -%s", f.Name) // Two spaces before -; see next two comments. - name, usage := flag.UnquoteUsage(f) - if len(name) > 0 { - s += " " + name - } - // Boolean flags of one ASCII letter are so common we - // treat them specially, putting their usage on the same line. - if len(s) <= 4 { // space, space, '-', 'x'. - s += "\t" - } else { - // Four spaces before the tab triggers good alignment - // for both 4- and 8-space tab stops. - s += "\n \t" - } - s += strings.ReplaceAll(usage, "\n", "\n \t") - - if !isZeroValue(f, f.DefValue) { - if _, ok := f.Value.(*stringValue); ok { - // put quotes on the value - s += fmt.Sprintf(" (default %q)", f.DefValue) - } else { - s += fmt.Sprintf(" (default %v)", f.DefValue) - } - } - fmt.Fprint(flag.CommandLine.Output(), s, "\n") - }) -} - -// isZeroValue determines whether the string represents the zero -// value for a flag. -// This code is copied from the stdlib. -func isZeroValue(f *flag.Flag, value string) bool { - // Build a zero value of the flag's Value type, and see if the - // result of calling its String method equals the value passed in. - // This works unless the Value type is itself an interface type. - typ := reflect.TypeOf(f.Value) - var z reflect.Value - if typ.Kind() == reflect.Ptr { - z = reflect.New(typ.Elem()) - } else { - z = reflect.Zero(typ) - } - return value == z.Interface().(flag.Value).String() -}