github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/container_unpause.go (about)

     1  /*
     2     Copyright The containerd Authors.
     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 main
    18  
    19  import (
    20  	"github.com/containerd/containerd"
    21  	"github.com/containerd/nerdctl/pkg/api/types"
    22  	"github.com/containerd/nerdctl/pkg/clientutil"
    23  	"github.com/containerd/nerdctl/pkg/cmd/container"
    24  
    25  	"github.com/spf13/cobra"
    26  )
    27  
    28  func newUnpauseCommand() *cobra.Command {
    29  	var unpauseCommand = &cobra.Command{
    30  		Use:               "unpause [flags] CONTAINER [CONTAINER, ...]",
    31  		Args:              cobra.MinimumNArgs(1),
    32  		Short:             "Unpause all processes within one or more containers",
    33  		RunE:              unpauseAction,
    34  		ValidArgsFunction: unpauseShellComplete,
    35  		SilenceUsage:      true,
    36  		SilenceErrors:     true,
    37  	}
    38  	return unpauseCommand
    39  }
    40  
    41  func processContainerUnpauseOptions(cmd *cobra.Command) (types.ContainerUnpauseOptions, error) {
    42  	globalOptions, err := processRootCmdFlags(cmd)
    43  	if err != nil {
    44  		return types.ContainerUnpauseOptions{}, err
    45  	}
    46  	return types.ContainerUnpauseOptions{
    47  		GOptions: globalOptions,
    48  		Stdout:   cmd.OutOrStdout(),
    49  	}, nil
    50  }
    51  
    52  func unpauseAction(cmd *cobra.Command, args []string) error {
    53  	options, err := processContainerUnpauseOptions(cmd)
    54  	if err != nil {
    55  		return err
    56  	}
    57  
    58  	client, ctx, cancel, err := clientutil.NewClient(cmd.Context(), options.GOptions.Namespace, options.GOptions.Address)
    59  	if err != nil {
    60  		return err
    61  	}
    62  	defer cancel()
    63  
    64  	return container.Unpause(ctx, client, args, options)
    65  }
    66  
    67  func unpauseShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
    68  	// show paused container names
    69  	statusFilterFn := func(st containerd.ProcessStatus) bool {
    70  		return st == containerd.Paused
    71  	}
    72  	return shellCompleteContainerNames(cmd, statusFilterFn)
    73  }