diff options
| author | John R. Lenton <jlenton@gmail.com> | 2016-09-09 00:31:53 +0100 |
|---|---|---|
| committer | John R. Lenton <jlenton@gmail.com> | 2016-09-10 15:34:53 +0100 |
| commit | 549851caa10d403ae0a7e9ccc02b8866ecf73966 (patch) | |
| tree | 09edb947d96b465f0245972056b00f628a76e362 | |
| parent | 5f6eb8b25694129abde957ca267eed89c1838276 (diff) | |
second pass, and review feedback (and fixed failing test)
| -rw-r--r-- | cmd/snap/cmd_create_key.go | 2 | ||||
| -rw-r--r-- | cmd/snap/cmd_find.go | 3 | ||||
| -rw-r--r-- | cmd/snap/cmd_find_test.go | 2 | ||||
| -rw-r--r-- | cmd/snap/cmd_list.go | 2 | ||||
| -rw-r--r-- | cmd/snap/cmd_list_test.go | 4 | ||||
| -rw-r--r-- | cmd/snap/cmd_run.go | 18 | ||||
| -rw-r--r-- | cmd/snap/cmd_set.go | 2 | ||||
| -rw-r--r-- | cmd/snap/cmd_sign_build.go | 7 | ||||
| -rw-r--r-- | cmd/snap/cmd_snap_op.go | 15 | ||||
| -rw-r--r-- | cmd/snap/main.go | 7 | ||||
| -rw-r--r-- | tests/main/searching/task.yaml | 2 |
11 files changed, 37 insertions, 27 deletions
diff --git a/cmd/snap/cmd_create_key.go b/cmd/snap/cmd_create_key.go index 0963834a0e..89c2fc3988 100644 --- a/cmd/snap/cmd_create_key.go +++ b/cmd/snap/cmd_create_key.go @@ -56,7 +56,7 @@ func (x *cmdCreateKey) Execute(args []string) error { keyName = "default" } if !asserts.IsValidAccountKeyName(keyName) { - return fmt.Errorf("key name %q is not valid; only ASCII letters, digits, and hyphens are allowed", keyName) + return fmt.Errorf(i18n.G("key name %q is not valid; only ASCII letters, digits, and hyphens are allowed"), keyName) } fmt.Fprint(Stdout, i18n.G("Passphrase: ")) diff --git a/cmd/snap/cmd_find.go b/cmd/snap/cmd_find.go index 106ab0dac9..bb93e2499f 100644 --- a/cmd/snap/cmd_find.go +++ b/cmd/snap/cmd_find.go @@ -37,6 +37,7 @@ The find command queries the store for available packages. func getPrice(prices map[string]float64, currency string) (float64, string, error) { // If there are no prices, then the snap is free if len(prices) == 0 { + // TRANSLATORS: free as in gratis return 0, "", errors.New(i18n.G("snap is free")) } @@ -102,7 +103,7 @@ func (x *cmdFind) Execute(args []string) error { } if x.Positional.Query == "" { - return errors.New(i18n.G("you need to specify a query. For example: snap find hello-world")) + return errors.New(i18n.G("you need to specify a query. Try \"snap find hello-world\".")) } return findSnaps(&client.FindOptions{ diff --git a/cmd/snap/cmd_find_test.go b/cmd/snap/cmd_find_test.go index 0516c14e56..be8b5636ae 100644 --- a/cmd/snap/cmd_find_test.go +++ b/cmd/snap/cmd_find_test.go @@ -33,7 +33,7 @@ func (s *SnapSuite) TestFindNothingFails(c *check.C) { c.Fatalf("it reached the server") }) _, err := snap.Parser().ParseArgs([]string{"find"}) - c.Assert(err, check.ErrorMatches, `you need to specify a query. For example.*`) + c.Assert(err, check.ErrorMatches, `you need to specify a query. Try.*`) } const findJSON = ` diff --git a/cmd/snap/cmd_list.go b/cmd/snap/cmd_list.go index 98a4eb5dcf..2617abc5ec 100644 --- a/cmd/snap/cmd_list.go +++ b/cmd/snap/cmd_list.go @@ -64,7 +64,7 @@ func listSnaps(names []string) error { snaps, err := cli.List(names) if err != nil { if err == client.ErrNoSnapsInstalled { - fmt.Fprintln(Stderr, i18n.G("No snaps are installed yet. Try 'snap install hello-world'.")) + fmt.Fprintln(Stderr, i18n.G("No snaps are installed yet. Try \"snap install hello-world\".")) return nil } return err diff --git a/cmd/snap/cmd_list_test.go b/cmd/snap/cmd_list_test.go index 17232e6395..4017407d42 100644 --- a/cmd/snap/cmd_list_test.go +++ b/cmd/snap/cmd_list_test.go @@ -69,7 +69,7 @@ func (s *SnapSuite) TestListEmpty(c *check.C) { c.Assert(err, check.IsNil) c.Assert(rest, check.DeepEquals, []string{}) c.Check(s.Stdout(), check.Equals, "") - c.Check(s.Stderr(), check.Matches, "No snaps are installed yet. Try 'snap install hello-world'.\n") + c.Check(s.Stderr(), check.Equals, "No snaps are installed yet. Try \"snap install hello-world\".\n") } func (s *SnapSuite) TestListEmptyWithQuery(c *check.C) { @@ -90,7 +90,7 @@ func (s *SnapSuite) TestListEmptyWithQuery(c *check.C) { c.Assert(err, check.IsNil) c.Assert(rest, check.DeepEquals, []string{}) c.Check(s.Stdout(), check.Equals, "") - c.Check(s.Stderr(), check.Matches, "No snaps are installed yet. Try 'snap install hello-world'.\n") + c.Check(s.Stderr(), check.Equals, "No snaps are installed yet. Try \"snap install hello-world\".\n") } func (s *SnapSuite) TestListWithNoMatchingQuery(c *check.C) { diff --git a/cmd/snap/cmd_run.go b/cmd/snap/cmd_run.go index c79fefe772..f43ef5a6a5 100644 --- a/cmd/snap/cmd_run.go +++ b/cmd/snap/cmd_run.go @@ -57,20 +57,21 @@ func init() { func (x *cmdRun) Execute(args []string) error { if len(args) == 0 { - return fmt.Errorf("need the application to run as argument") + return fmt.Errorf(i18n.G("need the application to run as argument")) } snapApp := args[0] args = args[1:] // Catch some invalid parameter combinations, provide helpful errors if x.Hook != "" && x.Command != "" { - return fmt.Errorf("cannot use --hook and --command together") + return fmt.Errorf(i18n.G("cannot use --hook and --command together")) } if x.Revision != "unset" && x.Revision != "" && x.Hook == "" { - return fmt.Errorf("-r can only be used with --hook") + return fmt.Errorf(i18n.G("-r can only be used with --hook")) } if x.Hook != "" && len(args) > 0 { - return fmt.Errorf("too many arguments for hook %q: %s", x.Hook, strings.Join(args, " ")) + // TRANSLATORS: %q is the hook name; %s a space-separated list of extra arguments + return fmt.Errorf(i18n.G("too many arguments for hook %q: %s"), x.Hook, strings.Join(args, " ")) } // Now actually handle the dispatching @@ -98,7 +99,7 @@ func getSnapInfo(snapName string, revision snap.Revision) (*snap.Info, error) { return nil, fmt.Errorf("cannot find snap %q", snapName) } if len(snaps) > 1 { - return nil, fmt.Errorf("multiple snaps for %q: %d", snapName, len(snaps)) + return nil, fmt.Errorf(i18n.G("multiple snaps for %q: %d"), snapName, len(snaps)) } revision = snaps[0].Revision } @@ -135,7 +136,7 @@ func snapExecEnv(info *snap.Info) []string { func createUserDataDirs(info *snap.Info) error { usr, err := userCurrent() if err != nil { - return fmt.Errorf("cannot get the current user: %s", err) + return fmt.Errorf(i18n.G("cannot get the current user: %v"), err) } // see snapenv.User @@ -143,7 +144,8 @@ func createUserDataDirs(info *snap.Info) error { commonUserData := info.UserCommonDataDir(usr.HomeDir) for _, d := range []string{userData, commonUserData} { if err := os.MkdirAll(d, 0755); err != nil { - return fmt.Errorf("cannot create %q: %s", d, err) + // TRANSLATORS: %q is the directory whose creation failed, %v the error message + return fmt.Errorf(i18n.G("cannot create %q: %v"), d, err) } } return nil @@ -158,7 +160,7 @@ func snapRunApp(snapApp, command string, args []string) error { app := info.Apps[appName] if app == nil { - return fmt.Errorf("cannot find app %q in %q", appName, snapName) + return fmt.Errorf(i18n.G("cannot find app %q in %q"), appName, snapName) } return runSnapConfine(info, app.SecurityTag(), snapApp, command, "", args) diff --git a/cmd/snap/cmd_set.go b/cmd/snap/cmd_set.go index a1d604668e..f3762f3428 100644 --- a/cmd/snap/cmd_set.go +++ b/cmd/snap/cmd_set.go @@ -50,7 +50,7 @@ func (x *cmdSet) Execute(args []string) error { for _, patchValue := range x.Positional.ConfValues { parts := strings.SplitN(patchValue, "=", 2) if len(parts) != 2 { - return fmt.Errorf("invalid configuration: %q (want key=value)", patchValue) + return fmt.Errorf(i18n.G("invalid configuration: %q (want key=value)"), patchValue) } var value interface{} err := json.Unmarshal([]byte(parts[1]), &value) diff --git a/cmd/snap/cmd_sign_build.go b/cmd/snap/cmd_sign_build.go index 88e70fb1ed..7e2b1fc18f 100644 --- a/cmd/snap/cmd_sign_build.go +++ b/cmd/snap/cmd_sign_build.go @@ -68,7 +68,8 @@ func (x *cmdSignBuild) Execute(args []string) error { gkm := asserts.NewGPGKeypairManager() privKey, err := gkm.GetByName(x.KeyName) if err != nil { - return fmt.Errorf("cannot use %q key: %v", x.KeyName, err) + // TRANSLATORS: %q is the key name, %v the error message + return fmt.Errorf(i18n.G("cannot use %q key: %v"), x.KeyName, err) } pubKey := privKey.PublicKey() @@ -88,12 +89,12 @@ func (x *cmdSignBuild) Execute(args []string) error { KeypairManager: gkm, }) if err != nil { - return fmt.Errorf("cannot open the assertions database: %v", err) + return fmt.Errorf(i18n.G("cannot open the assertions database: %v"), err) } a, err := adb.Sign(asserts.SnapBuildType, headers, nil, pubKey.ID()) if err != nil { - return fmt.Errorf("cannot sign assertion: %v", err) + return fmt.Errorf(i18n.G("cannot sign assertion: %v"), err) } _, err = Stdout.Write(asserts.Encode(a)) diff --git a/cmd/snap/cmd_snap_op.go b/cmd/snap/cmd_snap_op.go index 02e614a7a8..0dbb796cfe 100644 --- a/cmd/snap/cmd_snap_op.go +++ b/cmd/snap/cmd_snap_op.go @@ -69,7 +69,7 @@ func wait(client *client.Client, id string) (*client.Change, error) { if now.After(tMax) { return nil, err } - pb.Spin("Waiting for server to restart") + pb.Spin(i18n.G("Waiting for server to restart")) time.Sleep(pollTime) continue } @@ -453,7 +453,8 @@ func (x *cmdTry) Execute([]string) error { path, err := filepath.Abs(name) if err != nil { - return fmt.Errorf("cannot get full path for %q: %s", name, err) + // TRANSLATORS: %q gets what the user entered, %v gets the resulting error message + return fmt.Errorf(i18n.G("cannot get full path for %q: %v"), name, err) } changeID, err := cli.Try(path, opts) @@ -469,7 +470,8 @@ func (x *cmdTry) Execute([]string) error { // extract the snap name var snapName string if err := chg.Get("snap-name", &snapName); err != nil { - return fmt.Errorf("cannot extract the snap-name from local file %q: %s", name, err) + // TRANSLATORS: %q gets the snap name, %v gets the resulting error message + return fmt.Errorf(i18n.G("cannot extract the snap-name from local file %q: %v"), name, err) } name = snapName @@ -479,9 +481,11 @@ func (x *cmdTry) Execute([]string) error { return err } if len(snaps) != 1 { - return fmt.Errorf("cannot get data for %q: %v", name, snaps) + // TRANSLATORS: %q gets the snap name, %v the list of things found when trying to list it + return fmt.Errorf(i18n.G("cannot get data for %q: %v"), name, snaps) } snap := snaps[0] + // TRANSLATORS: 1. snap name, 2. snap version (keep those together please). the 3rd %s is a path (where it's mounted from). fmt.Fprintf(Stdout, i18n.G("%s %s mounted from %s\n"), name, snap.Version, path) return nil } @@ -578,7 +582,8 @@ func (x *cmdRevert) Execute(args []string) error { return err } if len(snaps) != 1 { - return fmt.Errorf("cannot get data for %q: %v", name, snaps) + // TRANSLATORS: %q gets the snap name, %v the list of things found when trying to list it + return fmt.Errorf(i18n.G("cannot get data for %q: %v"), name, snaps) } snap := snaps[0] fmt.Fprintf(Stdout, i18n.G("%s reverted to %s\n"), name, snap.Version) diff --git a/cmd/snap/main.go b/cmd/snap/main.go index d434202cdd..1cad10b4d4 100644 --- a/cmd/snap/main.go +++ b/cmd/snap/main.go @@ -51,7 +51,7 @@ type options struct { var optionsData options // ErrExtraArgs is returned if extra arguments to a command are found -var ErrExtraArgs = fmt.Errorf("too many arguments for command") +var ErrExtraArgs = fmt.Errorf(i18n.G("too many arguments for command")) // cmdInfo holds information needed to call parser.AddCommand(...). type cmdInfo struct { @@ -172,7 +172,7 @@ func Client() *client.Client { func init() { err := logger.SimpleSetup() if err != nil { - fmt.Fprintf(Stderr, "WARNING: failed to activate logging: %s\n", err) + fmt.Fprintf(Stderr, i18n.G("WARNING: failed to activate logging: %v\n"), err) } } @@ -235,7 +235,8 @@ func run() error { return fmt.Errorf(i18n.G(`%s (see "snap login --help")`), e.Message) } - return fmt.Errorf(i18n.G(`%s (try with sudo)`), e.Message) + // TRANSLATORS: %s will be a message along the lines of "login required" + return fmt.Errorf(i18n.G(`%s (try with sudo)`), i18n.G(e.Message)) } } diff --git a/tests/main/searching/task.yaml b/tests/main/searching/task.yaml index c29ad02dad..c7ec9ccda3 100644 --- a/tests/main/searching/task.yaml +++ b/tests/main/searching/task.yaml @@ -2,7 +2,7 @@ summary: Check snap search execute: | echo "Try to list all snaps" - ( snap find 2>&1 || echo FAILED ) | grep -Pzq "(?ms)empty query.*FAILED" + ( snap find 2>&1 || echo FAILED ) | grep -Pzq "(?ms)you need to specify a query.*FAILED" echo "Exact matches" for snapName in test-snapd-tools xkcd-webserver |
