github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/cmd/snap-repair/cmd_list.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 "text/tabwriter" 25 ) 26 27 func init() { 28 const ( 29 short = "Lists repairs run on this device" 30 long = "" 31 ) 32 33 if _, err := parser.AddCommand("list", short, long, &cmdList{}); err != nil { 34 panic(err) 35 } 36 37 } 38 39 type cmdList struct{} 40 41 func (c *cmdList) Execute([]string) error { 42 w := tabwriter.NewWriter(Stdout, 5, 3, 2, ' ', 0) 43 defer w.Flush() 44 45 // FIXME: this will not currently list the repairs that are 46 // skipped because of e.g. wrong architecture 47 48 // directory structure is: 49 // var/lib/snapd/run/repairs/ 50 // canonical/ 51 // 1/ 52 // r0.retry 53 // r0.script 54 // r1.done 55 // r1.script 56 // 2/ 57 // r3.done 58 // r3.script 59 repairTraces, err := newRepairTraces("*", "*") 60 if err != nil { 61 return err 62 } 63 if len(repairTraces) == 0 { 64 fmt.Fprintf(Stderr, "no repairs yet\n") 65 return nil 66 } 67 68 fmt.Fprintf(w, "Repair\tRev\tStatus\tSummary\n") 69 for _, t := range repairTraces { 70 fmt.Fprintf(w, "%s\t%v\t%s\t%s\n", t.Repair(), t.Revision(), t.Status(), t.Summary()) 71 } 72 73 return nil 74 }