MCPcopy Create free account
hub / github.com/algolia/cli / Dedent

Function Dedent

pkg/cmdutil/usage.go:176–200  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

174}
175
176func Dedent(s string) string {
177 lines := strings.Split(s, "\n")
178 minIndent := -1
179
180 for _, l := range lines {
181 if len(l) == 0 {
182 continue
183 }
184
185 indent := len(l) - len(strings.TrimLeft(l, " "))
186 if minIndent == -1 || indent < minIndent {
187 minIndent = indent
188 }
189 }
190
191 if minIndent <= 0 {
192 return s
193 }
194
195 var buf bytes.Buffer
196 for _, l := range lines {
197 fmt.Fprintln(&buf, strings.TrimPrefix(l, strings.Repeat(" ", minIndent)))
198 }
199 return strings.TrimSuffix(buf.String(), "\n")
200}
201
202func filterFlagSet(f pflag.FlagSet, flagsToDisplay []string) pflag.FlagSet {
203 filteredFlags := pflag.NewFlagSet("flags", pflag.ContinueOnError)

Callers 2

rootHelpFuncFunction · 0.92
AddInheritedFlagsMethod · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected