99 "github.com/arran4/strings2"
1010)
1111
12- func process (input string , output string , args []string , fn func (string , ... any ) (string , error )) {
12+ func process (input string , output string , args []string , fn func (string , ... any ) (string , error ), opts ... any ) {
1313 var in io.Reader
1414 if input == "-" {
1515 in = os .Stdin
@@ -33,7 +33,7 @@ func process(input string, output string, args []string, fn func(string, ...any)
3333 os .Exit (1 )
3434 }
3535
36- res , err := fn (string (b ))
36+ res , err := fn (string (b ), opts ... )
3737 if err != nil {
3838 fmt .Fprintf (os .Stderr , "Error processing: %v\n " , err )
3939 os .Exit (1 )
@@ -55,15 +55,57 @@ func process(input string, output string, args []string, fn func(string, ...any)
5555 fmt .Fprintln (out , res )
5656}
5757
58+ func buildOpts (delimiter string , screaming bool , whispering bool , firstUpper bool , firstLower bool , mixCaseSupport bool , noSmartAcronyms bool , numberSplitting bool , strict bool ) []any {
59+ var opts []any
60+ if delimiter != "" {
61+ opts = append (opts , strings2 .OptionDelimiter (delimiter ))
62+ }
63+ if screaming {
64+ opts = append (opts , strings2 .OptionCaseMode (strings2 .CMScreaming ))
65+ }
66+ if whispering {
67+ opts = append (opts , strings2 .OptionCaseMode (strings2 .CMWhispering ))
68+ }
69+ if firstUpper {
70+ opts = append (opts , strings2 .OptionFirstUpper ())
71+ }
72+ if firstLower {
73+ opts = append (opts , strings2 .OptionFirstLower ())
74+ }
75+ if mixCaseSupport {
76+ opts = append (opts , strings2 .OptionMixCaseSupport ())
77+ }
78+ if noSmartAcronyms {
79+ opts = append (opts , strings2 .WithSmartAcronyms (false ))
80+ }
81+ if numberSplitting {
82+ opts = append (opts , strings2 .WithNumberSplitting (true ))
83+ }
84+ if strict {
85+ opts = append (opts , strings2 .OptionStrict ())
86+ }
87+ return opts
88+ }
89+
5890// Camel is a subcommand `strings2 camel`
5991//
6092// Flags:
6193//
6294// input: -i --input (default: "") Input file or - for stdin
6395// output: -o --output (default: "") Output file or - for stdout
96+ // delimiter: -d --delimiter (default: "") Delimiter
97+ // screaming: -S --screaming (default: false) Screaming mode
98+ // whispering: -w --whispering (default: false) Whispering mode
99+ // firstUpper: -U --first-upper (default: false) First char upper
100+ // firstLower: -l --first-lower (default: false) First char lower
101+ // mixCaseSupport: -m --mix-case-support (default: false) Mix case support
102+ // noSmartAcronyms: --no-smart-acronyms (default: false) Disable smart acronyms
103+ // numberSplitting: --number-splitting (default: false) Enable number splitting
104+ // strict: --strict (default: false) Strict UTF8 mode
64105// args: ... String to convert if file/stdin not provided
65- func Camel (input string , output string , args ... string ) {
66- process (input , output , args , strings2 .ToCamel )
106+ func Camel (input string , output string , delimiter string , screaming bool , whispering bool , firstUpper bool , firstLower bool , mixCaseSupport bool , noSmartAcronyms bool , numberSplitting bool , strict bool , args ... string ) {
107+ opts := buildOpts (delimiter , screaming , whispering , firstUpper , firstLower , mixCaseSupport , noSmartAcronyms , numberSplitting , strict )
108+ process (input , output , args , strings2 .ToCamel , opts ... )
67109}
68110
69111// Snake is a subcommand `strings2 snake`
@@ -72,9 +114,19 @@ func Camel(input string, output string, args ...string) {
72114//
73115// input: -i --input (default: "") Input file or - for stdin
74116// output: -o --output (default: "") Output file or - for stdout
117+ // delimiter: -d --delimiter (default: "") Delimiter
118+ // screaming: -S --screaming (default: false) Screaming mode
119+ // whispering: -w --whispering (default: false) Whispering mode
120+ // firstUpper: -U --first-upper (default: false) First char upper
121+ // firstLower: -l --first-lower (default: false) First char lower
122+ // mixCaseSupport: -m --mix-case-support (default: false) Mix case support
123+ // noSmartAcronyms: --no-smart-acronyms (default: false) Disable smart acronyms
124+ // numberSplitting: --number-splitting (default: false) Enable number splitting
125+ // strict: --strict (default: false) Strict UTF8 mode
75126// args: ... String to convert if file/stdin not provided
76- func Snake (input string , output string , args ... string ) {
77- process (input , output , args , strings2 .ToSnake )
127+ func Snake (input string , output string , delimiter string , screaming bool , whispering bool , firstUpper bool , firstLower bool , mixCaseSupport bool , noSmartAcronyms bool , numberSplitting bool , strict bool , args ... string ) {
128+ opts := buildOpts (delimiter , screaming , whispering , firstUpper , firstLower , mixCaseSupport , noSmartAcronyms , numberSplitting , strict )
129+ process (input , output , args , strings2 .ToSnake , opts ... )
78130}
79131
80132// Kebab is a subcommand `strings2 kebab`
@@ -83,9 +135,19 @@ func Snake(input string, output string, args ...string) {
83135//
84136// input: -i --input (default: "") Input file or - for stdin
85137// output: -o --output (default: "") Output file or - for stdout
138+ // delimiter: -d --delimiter (default: "") Delimiter
139+ // screaming: -S --screaming (default: false) Screaming mode
140+ // whispering: -w --whispering (default: false) Whispering mode
141+ // firstUpper: -U --first-upper (default: false) First char upper
142+ // firstLower: -l --first-lower (default: false) First char lower
143+ // mixCaseSupport: -m --mix-case-support (default: false) Mix case support
144+ // noSmartAcronyms: --no-smart-acronyms (default: false) Disable smart acronyms
145+ // numberSplitting: --number-splitting (default: false) Enable number splitting
146+ // strict: --strict (default: false) Strict UTF8 mode
86147// args: ... String to convert if file/stdin not provided
87- func Kebab (input string , output string , args ... string ) {
88- process (input , output , args , strings2 .ToKebab )
148+ func Kebab (input string , output string , delimiter string , screaming bool , whispering bool , firstUpper bool , firstLower bool , mixCaseSupport bool , noSmartAcronyms bool , numberSplitting bool , strict bool , args ... string ) {
149+ opts := buildOpts (delimiter , screaming , whispering , firstUpper , firstLower , mixCaseSupport , noSmartAcronyms , numberSplitting , strict )
150+ process (input , output , args , strings2 .ToKebab , opts ... )
89151}
90152
91153// Pascal is a subcommand `strings2 pascal`
@@ -94,7 +156,17 @@ func Kebab(input string, output string, args ...string) {
94156//
95157// input: -i --input (default: "") Input file or - for stdin
96158// output: -o --output (default: "") Output file or - for stdout
159+ // delimiter: -d --delimiter (default: "") Delimiter
160+ // screaming: -S --screaming (default: false) Screaming mode
161+ // whispering: -w --whispering (default: false) Whispering mode
162+ // firstUpper: -U --first-upper (default: false) First char upper
163+ // firstLower: -l --first-lower (default: false) First char lower
164+ // mixCaseSupport: -m --mix-case-support (default: false) Mix case support
165+ // noSmartAcronyms: --no-smart-acronyms (default: false) Disable smart acronyms
166+ // numberSplitting: --number-splitting (default: false) Enable number splitting
167+ // strict: --strict (default: false) Strict UTF8 mode
97168// args: ... String to convert if file/stdin not provided
98- func Pascal (input string , output string , args ... string ) {
99- process (input , output , args , strings2 .ToPascal )
169+ func Pascal (input string , output string , delimiter string , screaming bool , whispering bool , firstUpper bool , firstLower bool , mixCaseSupport bool , noSmartAcronyms bool , numberSplitting bool , strict bool , args ... string ) {
170+ opts := buildOpts (delimiter , screaming , whispering , firstUpper , firstLower , mixCaseSupport , noSmartAcronyms , numberSplitting , strict )
171+ process (input , output , args , strings2 .ToPascal , opts ... )
100172}
0 commit comments