github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/cmd/snap/cmd_debug_bootvars.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2019 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  	"errors"
    24  
    25  	"github.com/jessevdk/go-flags"
    26  
    27  	"github.com/snapcore/snapd/boot"
    28  	"github.com/snapcore/snapd/i18n"
    29  	"github.com/snapcore/snapd/release"
    30  )
    31  
    32  type cmdBootvars struct {
    33  	UC20    bool   `long:"uc20"`
    34  	RootDir string `long:"root-dir"`
    35  }
    36  
    37  func init() {
    38  	cmd := addDebugCommand("boot-vars",
    39  		"(internal) obtain the snapd boot variables",
    40  		"(internal) obtain the snapd boot variables",
    41  		func() flags.Commander {
    42  			return &cmdBootvars{}
    43  		}, map[string]string{
    44  			"uc20":     i18n.G("Whether to use uc20 boot vars or not"),
    45  			"root-dir": i18n.G("Root directory to look for boot variables in"),
    46  		}, nil)
    47  	if release.OnClassic {
    48  		cmd.hidden = true
    49  	}
    50  }
    51  
    52  func (x *cmdBootvars) Execute(args []string) error {
    53  	if release.OnClassic {
    54  		return errors.New(`the "boot-vars" command is not available on classic systems`)
    55  	}
    56  	return boot.DumpBootVars(Stdout, x.RootDir, x.UC20)
    57  }