diff --git a/LICENSE b/LICENSE index fc3d712..f2ecdf9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ BSD 3-Clause License Copyright (c) 2019, Jérôme Renard +Copyright (c) 2022, Mohammad-Mohsen Aseman-Manzar All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index 0bb27cf..d62a76d 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ problem by obfuscating the string so it is no longer searchable with You can install mumbojumbo by running: go get github.com/jeromer/mumbojumbo/... + go install github.com/jeromer/mumbojumbo ## Usage @@ -94,6 +95,10 @@ see "some secret" Run `mumbojumbo --help` to get help +You can also use a text file as input: + + mumbojumbo -sf=/path/to/file -p=foo | goimports > foo.go + ## License This project is licensed under the BSD 3-Clause License - see the [LICENSE](LICENSE) file for details diff --git a/main.go b/main.go index ffe0a63..5308f4d 100644 --- a/main.go +++ b/main.go @@ -17,12 +17,12 @@ const ( ) var ( - s = flag.String("s", "", "string to obfuscate") - p = flag.String("p", "", "pkg name for the generated code") + s = flag.String("s", "", "string to obfuscate") + sf = flag.String("sf", "", "string file to obfuscate") + p = flag.String("p", "", "pkg name for the generated code") ) -var ( - tpl = `// CODE GENERATED BY mumbojumbo {{ .Version }} (https://github.com/jeromer/mumbojumbo) DO NOT EDIT !!!! +var tpl = `// CODE GENERATED BY mumbojumbo {{ .Version }} (https://github.com/jeromer/mumbojumbo) DO NOT EDIT !!!! package {{ .Pkg }} @@ -38,13 +38,24 @@ func Get() string { {{ .Obfuscated }} } ` -) func main() { flag.Parse() + var text string + if *s == "" { - quit("no string provided") + if *sf != "" { + b, err := os.ReadFile(*sf) + if err != nil { + quit(err.Error()) + } + text = string(b) + } else { + quit("no string provided") + } + } else { + text = *s } if *p == "" { @@ -56,7 +67,7 @@ func main() { tplData{ Version: VERSION, Pkg: *p, - Obfuscated: obfuscate(*s), + Obfuscated: obfuscate(text), }, ), ) @@ -77,7 +88,6 @@ func generateGoCode(data tplData) string { w := new(bytes.Buffer) err := tmpl.Execute(w, data) - if err != nil { panic(err) }