github.com/chipaca/snappy@v0.0.0-20210104084008-1f06296fe8ad/cmd/snap/cmd_delete_key.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package main
    21  
    22  import (
    23  	"github.com/jessevdk/go-flags"
    24  
    25  	"github.com/snapcore/snapd/asserts"
    26  	"github.com/snapcore/snapd/i18n"
    27  )
    28  
    29  type cmdDeleteKey struct {
    30  	Positional struct {
    31  		KeyName keyName
    32  	} `positional-args:"true" required:"true"`
    33  }
    34  
    35  func init() {
    36  	cmd := addCommand("delete-key",
    37  		i18n.G("Delete cryptographic key pair"),
    38  		i18n.G(`
    39  The delete-key command deletes the local cryptographic key pair with
    40  the given name.
    41  `),
    42  		func() flags.Commander {
    43  			return &cmdDeleteKey{}
    44  		}, nil, []argDesc{{
    45  			// TRANSLATORS: This needs to begin with < and end with >
    46  			name: i18n.G("<key-name>"),
    47  			// TRANSLATORS: This should not start with a lowercase letter.
    48  			desc: i18n.G("Name of key to delete"),
    49  		}})
    50  	cmd.hidden = true
    51  	cmd.completeHidden = true
    52  }
    53  
    54  func (x *cmdDeleteKey) Execute(args []string) error {
    55  	if len(args) > 0 {
    56  		return ErrExtraArgs
    57  	}
    58  
    59  	manager := asserts.NewGPGKeypairManager()
    60  	return manager.Delete(string(x.Positional.KeyName))
    61  }