gitee.com/mysnapcore/mysnapd@v0.1.0/cmd/snap/cmd_debug_gadget_disk_mapping.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2021 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  	"encoding/json"
    24  	"fmt"
    25  
    26  	"github.com/jessevdk/go-flags"
    27  
    28  	"gitee.com/mysnapcore/mysnapd/gadget"
    29  )
    30  
    31  type cmdGadgetDiskMapping struct {
    32  	clientMixin
    33  }
    34  
    35  func init() {
    36  	cmd := addDebugCommand("gadget-disk-mapping",
    37  		"(internal) obtain the gadget disk mapping",
    38  		"(internal) obtain the gadget disk mapping",
    39  		func() flags.Commander {
    40  			return &cmdGadgetDiskMapping{}
    41  		}, nil, nil)
    42  	cmd.hidden = true
    43  }
    44  
    45  func (x *cmdGadgetDiskMapping) Execute(args []string) error {
    46  	if len(args) > 0 {
    47  		return ErrExtraArgs
    48  	}
    49  	resp := map[string]gadget.DiskVolumeDeviceTraits{}
    50  	if err := x.client.DebugGet("gadget-disk-mapping", &resp, nil); err != nil {
    51  		return err
    52  	}
    53  	b, err := json.Marshal(resp)
    54  	if err != nil {
    55  		return err
    56  	}
    57  
    58  	fmt.Fprintf(Stdout, "%s\n", string(b))
    59  	return nil
    60  }