2020-04-02 17:48:47 +00:00
|
|
|
/*
|
|
|
|
Copyright 2020 The Kubernetes Authors All rights reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package generate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type rewrite struct {
|
|
|
|
flag string
|
|
|
|
description string
|
|
|
|
}
|
|
|
|
|
|
|
|
// rewriteFlags rewrites flags that are dependent on operating system
|
|
|
|
// for example, for `minikube start`, the description of --driver
|
|
|
|
// outputs possible drivers for the operating system
|
|
|
|
func rewriteFlags(command *cobra.Command, contents string) string {
|
|
|
|
rewrites := map[string][]rewrite{
|
|
|
|
"start": []rewrite{{
|
|
|
|
flag: "--driver",
|
|
|
|
description: "Used to specify the driver to run kubernetes in. The list of available drivers depends on operating system.",
|
2020-04-02 18:29:43 +00:00
|
|
|
}, {
|
|
|
|
flag: "--mount-string",
|
|
|
|
description: "The argument to pass the minikube mount command on start.",
|
2020-04-02 17:48:47 +00:00
|
|
|
}},
|
|
|
|
}
|
|
|
|
rws, ok := rewrites[command.Name()]
|
|
|
|
if !ok {
|
|
|
|
return contents
|
|
|
|
}
|
|
|
|
for _, r := range rws {
|
|
|
|
contents = rewriteFlag(contents, r.flag, r.description)
|
|
|
|
}
|
|
|
|
return contents
|
|
|
|
}
|
|
|
|
|
|
|
|
func rewriteFlag(contents, flag, description string) string {
|
|
|
|
lines := strings.Split(contents, "\n")
|
|
|
|
for i, l := range lines {
|
|
|
|
if strings.Contains(l, flag) {
|
|
|
|
// docs start with a prefix of 6 spaces
|
|
|
|
replacement := " "
|
|
|
|
replacement += flag
|
2020-04-02 17:57:05 +00:00
|
|
|
// there are 36 spaces between the start of the flag name
|
|
|
|
// and the description
|
|
|
|
spacesBetween := 36 - len(flag)
|
2020-04-02 17:48:47 +00:00
|
|
|
for i := 0; i < spacesBetween; i++ {
|
|
|
|
replacement += " "
|
|
|
|
}
|
|
|
|
replacement += description
|
|
|
|
lines[i] = replacement
|
|
|
|
}
|
|
|
|
}
|
2020-04-02 17:57:05 +00:00
|
|
|
return strings.Join(lines, "\n")
|
2020-04-02 17:48:47 +00:00
|
|
|
}
|