Skip to content

Commit

Permalink
Update flags
Browse files Browse the repository at this point in the history
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
  • Loading branch information
riyazdf committed Sep 15, 2016
1 parent a042f1e commit e123918
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cmd/notary/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ func TestWitness(t *testing.T) {
// 12. check non-targets base roles all fail
for _, role := range []string{data.CanonicalRootRole, data.CanonicalSnapshotRole, data.CanonicalTimestampRole} {
// clear any pending changes to ensure errors are only related to the specific role we're trying to witness
_, err = runCommand(t, tempDir, "reset", "gun")
_, err = runCommand(t, tempDir, "reset", "gun", "--all")
require.NoError(t, err)

_, err = runCommand(t, tempDir, "witness", "gun", role)
Expand All @@ -1618,7 +1618,7 @@ func TestWitness(t *testing.T) {
// 13. test auto-publish functionality (just for witness)

// purge the old staged witness
_, err = runCommand(t, tempDir, "reset", "gun")
_, err = runCommand(t, tempDir, "reset", "gun", "--all")
require.NoError(t, err)

// remove key2 and add back key1
Expand Down
2 changes: 1 addition & 1 deletion cmd/notary/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ var exampleValidCommands = []string{
"init repo",
"list repo",
"status repo",
"reset repo",
"reset repo --all",
"publish repo",
"add repo v1 somefile",
"addhash repo targetv1 --sha256 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 10",
Expand Down
15 changes: 10 additions & 5 deletions cmd/notary/tuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type tufCommander struct {
output string
quiet bool

resetAll bool
deleteIdx []int
archiveChangelist string

Expand All @@ -133,7 +134,8 @@ func (t *tufCommander) AddToCommand(cmd *cobra.Command) {
cmd.AddCommand(cmdTUFStatusTemplate.ToCommand(t.tufStatus))

cmdReset := cmdTUFResetTemplate.ToCommand(t.tufReset)
cmdReset.Flags().IntSliceVarP(&t.deleteIdx, "unstage", "u", nil, "Numbers of specific changes to exclusively delete, as shown in status list")
cmdReset.Flags().IntSliceVarP(&t.deleteIdx, "number", "n", nil, "Numbers of specific changes to exclusively reset, as shown in status list")
cmdReset.Flags().BoolVar(&t.resetAll, "all", false, "Reset all changes shown in the status list")
cmd.AddCommand(cmdReset)

cmd.AddCommand(cmdTUFPublishTemplate.ToCommand(t.tufPublish))
Expand Down Expand Up @@ -589,6 +591,10 @@ func (t *tufCommander) tufReset(cmd *cobra.Command, args []string) error {
cmd.Usage()
return fmt.Errorf("Must specify a GUN")
}
if !t.resetAll && len(t.deleteIdx) < 1 {
cmd.Usage()
return fmt.Errorf("Must specify changes to reset with -n or the --all flag")
}

config, err := t.configGetter()
if err != nil {
Expand All @@ -612,11 +618,10 @@ func (t *tufCommander) tufReset(cmd *cobra.Command, args []string) error {
return err
}


if len(t.deleteIdx) > 0 {
return cl.Remove(t.deleteIdx)
if t.resetAll {
return cl.Clear(t.archiveChangelist)
}
return cl.Clear(t.archiveChangelist)
return cl.Remove(t.deleteIdx)
}

func (t *tufCommander) tufPublish(cmd *cobra.Command, args []string) error {
Expand Down
8 changes: 5 additions & 3 deletions cmd/notary/tuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ func TestStatusUnstageAndReset(t *testing.T) {
}

// run a reset with an empty changelist and make sure it succeeds
err := tc.tufStatus(&cobra.Command{}, []string{"gun"})
tc.resetAll = true
err := tc.tufReset(&cobra.Command{}, []string{"gun"})
require.NoError(t, err)

// add some targets
Expand All @@ -161,7 +162,7 @@ func TestStatusUnstageAndReset(t *testing.T) {
require.Contains(t, out, "test3")
require.Contains(t, out, "test4")

_, err = runCommand(t, tempBaseDir, "reset", "gun", "--unstage", "-1,1,3,10")
_, err = runCommand(t, tempBaseDir, "reset", "gun", "-n", "-1,1,3,10")
require.NoError(t, err)

out, err = runCommand(t, tempBaseDir, "status", "gun")
Expand All @@ -171,7 +172,7 @@ func TestStatusUnstageAndReset(t *testing.T) {
require.Contains(t, out, "test3")
require.NotContains(t, out, "test4")

_, err = runCommand(t, tempBaseDir, "reset", "gun")
_, err = runCommand(t, tempBaseDir, "reset", "gun", "--all")
require.NoError(t, err)

out, err = runCommand(t, tempBaseDir, "status", "gun")
Expand Down Expand Up @@ -204,6 +205,7 @@ func TestGetTrustPinningErrors(t *testing.T) {
},
}
require.Error(t, tc.tufStatus(&cobra.Command{}, []string{"gun"}))
tc.resetAll = true
require.Error(t, tc.tufReset(&cobra.Command{}, []string{"gun"}))
require.Error(t, tc.tufDeleteGUN(&cobra.Command{}, []string{"gun"}))
require.Error(t, tc.tufInit(&cobra.Command{}, []string{"gun"}))
Expand Down
4 changes: 2 additions & 2 deletions docs/command_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ You can view staged changes with `notary status` and unstage them with `notary r
$ notary status <GUN>
# Unstage a specific change
$ notary reset <GUN> --unstage 0
$ notary reset <GUN> -n 0
# Alternatively, reset all changes
$ notary reset <GUN>
$ notary reset <GUN> --all
```
When you're ready to publish your changes to the Notary server, run:
Expand Down
8 changes: 4 additions & 4 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ $ notary -s https://notary.docker.io -d ~/.docker/trust publish docker.io/libra

Note that each row in the status has a number associated with it, found in the first
column. This number can be used to remove individual changes from the changelist if
they are no longer desired. This is done using the `reset` command and its `--unstage` flag:
they are no longer desired. This is done using the `reset` command:

```
$ notary -d ~/.docker/trust status docker.io/library/alpine
Expand All @@ -154,7 +154,7 @@ Unpublished changes for docker.io/library/alpine:
\- ------ ----- ---- ----
0 delete targets target 2.6
1 create targets target 3.0
$ notary -d ~/.docker/trust reset docker.io/library/alpine --unstage 0
$ notary -d ~/.docker/trust reset docker.io/library/alpine -n 0
Unpublished changes for docker.io/library/alpine:
\# ACTION SCOPE TYPE PATH
Expand All @@ -163,12 +163,12 @@ Unpublished changes for docker.io/library/alpine:
```

Pay close attention to how the indices are updated as changes are removed. You may
pass multiple `--unstage` flags with multiple indices in a single invocation of the
pass multiple `-n` flags with multiple indices in a single invocation of the
`reset` subcommand and they will all be handled correctly within that invocation. Between
invocations however, you should list the changes again to check which indices you want
to remove.

It is also possible to completely clear all pending changes by not passing any flags
It is also possible to completely clear all pending changes by passing the `--all` flag
to the `reset` subcommand. This deletes all pending changes for the specified GUN.

## Configure the client
Expand Down

0 comments on commit e123918

Please sign in to comment.