github.com/chipaca/snappy@v0.0.0-20210104084008-1f06296fe8ad/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  
    28  type cmdGetBaseDeclaration struct {
    29  	get bool
    30  	clientMixin
    31  }
    32  
    33  func init() {
    34  	cmd := addDebugCommand("get-base-declaration",
    35  		"(internal) obtain the base declaration for all interfaces (deprecated)",
    36  		"(internal) obtain the base declaration for all interfaces (deprecated)",
    37  		func() flags.Commander {
    38  			return &cmdGetBaseDeclaration{}
    39  		}, nil, nil)
    40  	cmd.hidden = true
    41  
    42  	cmd = addDebugCommand("base-declaration",
    43  		"(internal) obtain the base declaration for all interfaces",
    44  		"(internal) obtain the base declaration for all interfaces",
    45  		func() flags.Commander {
    46  			return &cmdGetBaseDeclaration{get: true}
    47  		}, nil, nil)
    48  	cmd.hidden = true
    49  }
    50  
    51  func (x *cmdGetBaseDeclaration) Execute(args []string) error {
    52  	if len(args) > 0 {
    53  		return ErrExtraArgs
    54  	}
    55  	var resp struct {
    56  		BaseDeclaration string `json:"base-declaration"`
    57  	}
    58  	var err error
    59  	if x.get {
    60  		err = x.client.DebugGet("base-declaration", &resp, nil)
    61  	} else {
    62  		err = x.client.Debug("get-base-declaration", nil, &resp)
    63  	}
    64  	if err != nil {
    65  		return err
    66  	}
    67  	fmt.Fprintf(Stdout, "%s\n", resp.BaseDeclaration)
    68  	return nil
    69  }