-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_helpers.go
More file actions
38 lines (34 loc) · 902 Bytes
/
example_helpers.go
File metadata and controls
38 lines (34 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) Codesphere Inc.
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"strings"
"github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/internal/version"
)
// formatExamples builds an Example string similar to io.FormatExampleCommands
// it prefixes commands with a stable binary name (e.g. "oms") instead of temporary go-build paths
func formatExamples(cmdName string, examples []io.Example) string {
var b strings.Builder
for i, ex := range examples {
if ex.Desc != "" {
b.WriteString("# ")
b.WriteString(ex.Desc)
b.WriteString("\n")
}
b.WriteString("$ ")
build := version.Build{}
b.WriteString(build.BinName())
b.WriteString(" ")
b.WriteString(cmdName)
if ex.Cmd != "" {
b.WriteString(" ")
b.WriteString(ex.Cmd)
}
b.WriteString("\n")
if i < len(examples)-1 {
b.WriteString("\n")
}
}
return b.String()
}