-
Notifications
You must be signed in to change notification settings - Fork 562
/
cmd_repair_repairs.go
97 lines (81 loc) · 2.55 KB
/
cmd_repair_repairs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2017 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/jessevdk/go-flags"
"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/i18n"
"github.com/snapcore/snapd/release"
)
func runSnapRepair(cmdStr string, args []string) error {
// do not even try to run snap-repair on classic, some distros
// may not even package it
if release.OnClassic {
return fmt.Errorf(i18n.G("repairs are not available on a classic system"))
}
snapRepairPath := filepath.Join(dirs.GlobalRootDir, dirs.CoreLibExecDir, "snap-repair")
args = append([]string{cmdStr}, args...)
cmd := exec.Command(snapRepairPath, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
type cmdShowRepair struct {
Positional struct {
Repair []string `positional-arg-name:"<repair>"`
} `positional-args:"yes"`
}
var shortRepairHelp = i18n.G("Show specific repairs")
var longRepairHelp = i18n.G(`
The repair command shows the details about one or multiple repairs.
`)
func init() {
cmd := addCommand("repair", shortRepairHelp, longRepairHelp, func() flags.Commander {
return &cmdShowRepair{}
}, nil, nil)
if release.OnClassic {
cmd.hidden = true
}
}
func (x *cmdShowRepair) Execute(args []string) error {
if len(x.Positional.Repair) == 0 {
return fmt.Errorf("no <repair-id> given. Try 'snap repairs' to list all repairs or specify a specific repair id.")
}
return runSnapRepair("show", x.Positional.Repair)
}
type cmdListRepairs struct{}
var shortRepairsHelp = i18n.G("Lists all repairs")
var longRepairsHelp = i18n.G(`
The repairs command lists all processed repairs for this device.
`)
func init() {
cmd := addCommand("repairs", shortRepairsHelp, longRepairsHelp, func() flags.Commander {
return &cmdListRepairs{}
}, nil, nil)
if release.OnClassic {
cmd.hidden = true
}
}
func (x *cmdListRepairs) Execute(args []string) error {
return runSnapRepair("list", args)
}