github.com/splunk/dan1-qbec@v0.7.3/internal/commands/examples.go (about)

     1  /*
     2     Copyright 2019 Splunk Inc.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package commands
    18  
    19  import "strings"
    20  
    21  type example struct {
    22  	command  string
    23  	comments []string
    24  }
    25  
    26  func (e example) String() string {
    27  	if len(e.comments) == 0 {
    28  		return e.command
    29  	}
    30  	var prefixed []string
    31  	for _, c := range e.comments {
    32  		prefixed = append(prefixed, "# "+c)
    33  	}
    34  	return strings.Join(prefixed, "\n") + "\n" + e.command
    35  }
    36  
    37  func newExample(command string, comments ...string) example {
    38  	return example{command: "qbec " + command, comments: comments}
    39  }
    40  
    41  func exampleHelp(examples ...example) string {
    42  	var ret []string
    43  	for _, eg := range examples {
    44  		ret = append(ret, eg.String())
    45  	}
    46  	return "\n" + strings.Join(ret, "\n\n")
    47  }
    48  
    49  func applyExamples() string {
    50  	return exampleHelp(
    51  		newExample("apply dev --yes --wait", "create/ update all dev components and delete extra objects on the server",
    52  			"do not ask for confirmation, wait until all objects have a ready status"),
    53  		newExample("apply -n dev", "show what apply would do for the dev environment"),
    54  		newExample("apply dev -c redis -K secret", "update all objects except secrets just for the redis component"),
    55  		newExample("apply dev --gc=false", "only create/ update, do not delete extra objects from the server"),
    56  	)
    57  }
    58  
    59  func showExamples() string {
    60  	return exampleHelp(
    61  		newExample("show dev", "show all components for the 'dev' environment in YAML"),
    62  		newExample("show dev -c postgres -c redis -o json", "expand just 2 components and output JSON"),
    63  		newExample("show dev -C postgres -C redis", "expand all but 2 components"),
    64  		newExample("show dev -k deployment -k configmap", "show only deployments and config maps"),
    65  		newExample("show dev -K secret", "show all objects except secrets"),
    66  		newExample("show dev -O", "list all objects for the dev environment"),
    67  	)
    68  }
    69  
    70  func deleteExamples() string {
    71  	return exampleHelp(
    72  		newExample("delete dev", "delete all objects created for the dev environment"),
    73  		newExample("delete -n dev", "show objects that would be deleted for the dev environment"),
    74  		newExample("delete dev -c redis -k secret", "delete all secrets for the redis component"),
    75  		newExample("delete dev --local", "use object names from local component files for deletion list",
    76  			"by default, the list is produced using server queries"),
    77  	)
    78  }
    79  
    80  func diffExamples() string {
    81  	return exampleHelp(
    82  		newExample("diff dev", "show differences between local and remote objects for the dev environment"),
    83  		newExample("diff dev -c redis --show-deletes=false", "show differences for the redis component for the dev environment",
    84  			"ignore extra remote objects"),
    85  		newExample("diff dev -ignore-all-labels", "do not take labels into account when calculating the diff"),
    86  	)
    87  }
    88  
    89  func validateExamples() string {
    90  	return exampleHelp(
    91  		newExample("validate dev", "validate all objects for all components against the dev environment"),
    92  	)
    93  }
    94  
    95  func componentListExamples() string {
    96  	return exampleHelp(
    97  		newExample("component list dev", "list all components for the dev environment"),
    98  		newExample("component list dev -O", "list all objects for the dev environment"),
    99  		newExample("component list _", "list all baseline components"),
   100  	)
   101  }
   102  
   103  func componentDiffExamples() string {
   104  	return exampleHelp(
   105  		newExample("component diff dev", "show differences in component lists between baseline and dev"),
   106  		newExample("component diff dev prod -O", "show differences in object lists between dev and prod"),
   107  	)
   108  }
   109  
   110  func paramListExamples() string {
   111  	return exampleHelp(
   112  		newExample("param list dev", "list all parameters for the dev environment"),
   113  		newExample("param list _", "list baseline parameters for all components"),
   114  		newExample("param list dev -c redis", "list parameters for the redis component for the dev environment"),
   115  	)
   116  }
   117  
   118  func paramDiffExamples() string {
   119  	return exampleHelp(
   120  		newExample("param diff dev", "show differences in parameter values between baseline and dev"),
   121  		newExample("param diff dev prod", "show differences in parameter values  between dev and prod"),
   122  	)
   123  }
   124  
   125  func envListExamples() string {
   126  	return exampleHelp(
   127  		newExample("env list", "list all environment names, one per line in sorted order"),
   128  		newExample("env list -o json", "list all environments in JSON format, (use -o yaml for YAML)"),
   129  	)
   130  }
   131  
   132  func envVarsExamples() string {
   133  	return exampleHelp(
   134  		newExample("env vars <env>", "print kubernetes variables for env in eval format, run as `eval $(qbec env vars env)`"),
   135  		newExample("env vars -o json", "print kubernetes variables for env in JSON format, (use -o yaml for YAML)"),
   136  	)
   137  }