github.com/rigado/snapd@v2.42.5-go-mod+incompatible/cmd/snap-repair/main.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 "io" 25 "os" 26 27 // TODO: consider not using go-flags at all 28 "github.com/jessevdk/go-flags" 29 30 "github.com/snapcore/snapd/cmd" 31 "github.com/snapcore/snapd/httputil" 32 "github.com/snapcore/snapd/logger" 33 "github.com/snapcore/snapd/release" 34 ) 35 36 var ( 37 Stdout io.Writer = os.Stdout 38 Stderr io.Writer = os.Stderr 39 40 opts struct{} 41 parser *flags.Parser = flags.NewParser(&opts, flags.HelpFlag|flags.PassDoubleDash|flags.PassAfterNonOption) 42 ) 43 44 const ( 45 shortHelp = "Repair an Ubuntu Core system" 46 longHelp = ` 47 snap-repair is a tool to fetch and run repair assertions 48 which are used to do emergency repairs on the device. 49 ` 50 ) 51 52 func init() { 53 err := logger.SimpleSetup() 54 if err != nil { 55 fmt.Fprintf(Stderr, "WARNING: failed to activate logging: %v\n", err) 56 } 57 } 58 59 var errOnClassic = fmt.Errorf("cannot use snap-repair on a classic system") 60 61 func main() { 62 if err := run(); err != nil { 63 fmt.Fprintf(Stderr, "error: %v\n", err) 64 if err != errOnClassic { 65 os.Exit(1) 66 } 67 } 68 } 69 70 func run() error { 71 if release.OnClassic { 72 return errOnClassic 73 } 74 httputil.SetUserAgentFromVersion(cmd.Version, "snap-repair") 75 76 if err := parseArgs(os.Args[1:]); err != nil { 77 return err 78 } 79 80 return nil 81 } 82 83 func parseArgs(args []string) error { 84 parser.ShortDescription = shortHelp 85 parser.LongDescription = longHelp 86 87 _, err := parser.ParseArgs(args) 88 return err 89 }