1/*
2Copyright 2016 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package rollout
18
19import (
20	"github.com/lithammer/dedent"
21	"github.com/spf13/cobra"
22
23	"k8s.io/cli-runtime/pkg/genericclioptions"
24	cmdutil "k8s.io/kubectl/pkg/cmd/util"
25	"k8s.io/kubectl/pkg/util/i18n"
26	"k8s.io/kubectl/pkg/util/templates"
27)
28
29var (
30	rolloutLong = templates.LongDesc(i18n.T(`
31		Manage the rollout of a resource.`) + rolloutValidResources)
32
33	rolloutExample = templates.Examples(`
34		# Rollback to the previous deployment
35		kubectl rollout undo deployment/abc
36
37		# Check the rollout status of a daemonset
38		kubectl rollout status daemonset/foo`)
39
40	rolloutValidResources = dedent.Dedent(`
41		Valid resource types include:
42
43		   * deployments
44		   * daemonsets
45		   * statefulsets
46		`)
47)
48
49// NewCmdRollout returns a Command instance for 'rollout' sub command
50func NewCmdRollout(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
51	cmd := &cobra.Command{
52		Use:                   "rollout SUBCOMMAND",
53		DisableFlagsInUseLine: true,
54		Short:                 i18n.T("Manage the rollout of a resource"),
55		Long:                  rolloutLong,
56		Example:               rolloutExample,
57		Run:                   cmdutil.DefaultSubCommandRun(streams.Out),
58	}
59	// subcommands
60	cmd.AddCommand(NewCmdRolloutHistory(f, streams))
61	cmd.AddCommand(NewCmdRolloutPause(f, streams))
62	cmd.AddCommand(NewCmdRolloutResume(f, streams))
63	cmd.AddCommand(NewCmdRolloutUndo(f, streams))
64	cmd.AddCommand(NewCmdRolloutStatus(f, streams))
65	cmd.AddCommand(NewCmdRolloutRestart(f, streams))
66
67	return cmd
68}
69