github.com/Lephar/snapd@v0.0.0-20210825215435-c7fba9cef4d2/cmd/snap/cmd_repair_repairs.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 "os" 25 "os/exec" 26 "path/filepath" 27 28 "github.com/jessevdk/go-flags" 29 30 "github.com/snapcore/snapd/dirs" 31 "github.com/snapcore/snapd/i18n" 32 "github.com/snapcore/snapd/release" 33 ) 34 35 func runSnapRepair(cmdStr string, args []string) error { 36 // do not even try to run snap-repair on classic, some distros 37 // may not even package it 38 if release.OnClassic { 39 return fmt.Errorf(i18n.G("repairs are not available on a classic system")) 40 } 41 42 snapRepairPath := filepath.Join(dirs.GlobalRootDir, dirs.CoreLibExecDir, "snap-repair") 43 args = append([]string{cmdStr}, args...) 44 cmd := exec.Command(snapRepairPath, args...) 45 cmd.Stdin = os.Stdin 46 cmd.Stdout = os.Stdout 47 cmd.Stderr = os.Stderr 48 return cmd.Run() 49 } 50 51 type cmdShowRepair struct { 52 Positional struct { 53 Repair []string `positional-arg-name:"<repair>"` 54 } `positional-args:"yes"` 55 } 56 57 var shortRepairHelp = i18n.G("Show specific repairs") 58 var longRepairHelp = i18n.G(` 59 The repair command shows the details about one or multiple repairs. 60 `) 61 62 func init() { 63 cmd := addCommand("repair", shortRepairHelp, longRepairHelp, func() flags.Commander { 64 return &cmdShowRepair{} 65 }, nil, nil) 66 if release.OnClassic { 67 cmd.hidden = true 68 } 69 } 70 71 func (x *cmdShowRepair) Execute(args []string) error { 72 if len(x.Positional.Repair) == 0 { 73 return fmt.Errorf("no <repair-id> given. Try 'snap repairs' to list all repairs or specify a specific repair id.") 74 } 75 76 return runSnapRepair("show", x.Positional.Repair) 77 } 78 79 type cmdListRepairs struct{} 80 81 var shortRepairsHelp = i18n.G("Lists all repairs") 82 var longRepairsHelp = i18n.G(` 83 The repairs command lists all processed repairs for this device. 84 `) 85 86 func init() { 87 cmd := addCommand("repairs", shortRepairsHelp, longRepairsHelp, func() flags.Commander { 88 return &cmdListRepairs{} 89 }, nil, nil) 90 if release.OnClassic { 91 cmd.hidden = true 92 } 93 } 94 95 func (x *cmdListRepairs) Execute(args []string) error { 96 return runSnapRepair("list", args) 97 }