github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/cmd/snap/cmd_get_base_declaration.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2017 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  	"fmt"
    24  
    25  	"github.com/jessevdk/go-flags"
    26  
    27  	"github.com/snapcore/snapd/i18n"
    28  )
    29  
    30  type cmdGetBaseDeclaration struct {
    31  	get bool
    32  	clientMixin
    33  }
    34  
    35  func init() {
    36  	cmd := addDebugCommand("get-base-declaration",
    37  		"(internal) obtain the base declaration for all interfaces (deprecated)",
    38  		"(internal) obtain the base declaration for all interfaces (deprecated)",
    39  		func() flags.Commander {
    40  			return &cmdGetBaseDeclaration{get: true}
    41  		}, nil, nil)
    42  	cmd.hidden = true
    43  
    44  	cmd = addDebugCommand("base-declaration",
    45  		"(internal) obtain the base declaration for all interfaces",
    46  		"(internal) obtain the base declaration for all interfaces",
    47  		func() flags.Commander {
    48  			return &cmdGetBaseDeclaration{}
    49  		}, nil, nil)
    50  	cmd.hidden = true
    51  }
    52  
    53  func (x *cmdGetBaseDeclaration) Execute(args []string) error {
    54  	if len(args) > 0 {
    55  		return ErrExtraArgs
    56  	}
    57  	var resp struct {
    58  		BaseDeclaration string `json:"base-declaration"`
    59  	}
    60  	var err error
    61  	err = x.client.DebugGet("base-declaration", &resp, nil)
    62  	if err != nil {
    63  		return err
    64  	}
    65  	fmt.Fprintf(Stdout, "%s\n", resp.BaseDeclaration)
    66  	if x.get {
    67  		fmt.Fprintf(Stderr, i18n.G("'snap debug get-base-declaration' is deprecated; use 'snap debug base-declaration'."))
    68  	}
    69  	return nil
    70  }