]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
Use VersionsFromString instead of VersionsFromArgs
authorGeorge Dunlap <george.dunlap@citrix.com>
Tue, 31 Jul 2018 10:52:26 +0000 (11:52 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Tue, 31 Jul 2018 10:53:37 +0000 (11:53 +0100)
Update README.md with the new interface.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
README.md
main.go
test.go
xsa.go

index d091ebd235ecda9d05d62d9e9f1a4df987bfd015..1dd96bf9a6b673aae0f801fd1147f2dafe6a7cb3 100644 (file)
--- a/README.md
+++ b/README.md
@@ -136,6 +136,17 @@ that contains the actual fix.
 Other branches may be made as a part of operations, but will always have the
 `xsa/` prefix (e.g., `xsa/tmp`).
 
+## Command-line conventions
+
+Some commands accept a `<versionlist>`.  This can be:
+ - A single version; e.g., `4.7` or `master`
+ - `all`, which will include all versions listed in the XSA
+ - A range with two versions; e.g., `4.11..4.9`.  This range **MUST**
+   be high to low.  The first version can be `master`.
+ - A range with only one version. `4.10..` for instance will be all
+   versions for this XSA older than 4.10 (inclusive).  `..4.8` will be
+   all versions for this XSA newer than 4.8 (inclusive).
+
 ## Generating patches from a branch
 
 To create a set of patches for a particular xen version for a
@@ -235,7 +246,7 @@ chance to inspect and test the backport.
 The developer repeats `xsatool 213 backport` until all backports have
 been made.
 
-`xsatool 213 sync-patches`
+`xsatool 213 sync-patches [<versionlist>]`
 
 For each version for which `xsa/213/${v}` exists, this will:
 
@@ -245,6 +256,9 @@ For each version for which `xsa/213/${v}` exists, this will:
 
  - Update the recipe for that version in `xsa213.meta`
  
+If `<versionlist>` is supplied, it will be limited to the range
+specified.
 `xsatool 213 dedup-patches`
  
 Sync-patches will always generate a separate set of patches for each
@@ -330,23 +344,22 @@ for supported versions 4.5 and earlier.
 
 ## Checking patches before sending them out
 
-`xsatool 213 test-apply`
+`xsatool 213 test-apply [<versionlist>]`
 
-For each version for which patches exist in `xsa213.meta`, it creates
-`test/213/$v-stable`, `test/213/$v-baseline`, and `test/213/$v`
+For each version in `<versionlist>` , it creates `test/213/$v-stable`,
+`test/213/$v-baseline`, and `test/213/$v`.  (If no `<versionlist>` is
+supplied, it defaults to `all`.)
 
 Individual versions can be specified as well: `xsatool 213 test-apply 4.6 4.5`
 
-`xsatool 213 test-build`
+`xsatool 213 test-build [<versionlist>]`
 
-For each version for which patches exist in `xsa213.meta`, it will
-attempt to check out a tree based on `test/213/$v` and do a build.  If
-the branch does not exist it will throw an error.
+For each version in `<versionlist>`, it will attempt to check out a
+tree based on `test/213/$v` and do a build.  If the branch does not
+exist it will throw an error.  (If no `<versionlist>` is supplied, it
+defaults to `all`.)
 
-As with `test-apply`, you can also specify individual versions:
-`xsatool 213 test-build 4.5`
-
-`xsatool 213 test`
+`xsatool 213 test [<versionlist>]`
 
 Do both `test-apply` and `test-build` (i.e., a full test) for each
 version.
@@ -360,15 +373,12 @@ want to update your copy.
 Assuming the developer has checked her changes into `xsa.git`, update
 your copy of `xsa.git`, and then
 
-`xsatool 213 sync-branch`
+`xsatool 213 sync-branch [<versionlist>]`
 
 For each version specified, it will reset all branches (`-stable`,
 `-baseline`, and patch branch) according to the updated recipe in
-`xsa213.meta`.
-
-As with `sync-patches`, you can either specify a specific version, or
-you can leave the version blank and it will make branches for versions
-*for which recipes exist*.
+`xsa213.meta`.  If no `<versionlist>` is supplied, it
+defaults to `all`.
 
 This could also be useful, for example, if prerequisites are manually
 added or removed.
@@ -382,12 +392,13 @@ branch named `staging-*` and to a 'merge --ff-only'.
 
 ## Updating the 'base' of an outstanding XSA when the stable branches have changed
 
-`xsatool NNN reset-base [versions]`
+`xsatool NNN reset-base <[versionlist]>`
 
 For each version, this will update StableRef to point to the current
 value of the 'stable' branch (either `master` or `stable-VV`).  It
 will then re-apply the patch and any prerequisites as-is (i.e., *not*
-doing a rebase), failing out in case of an error.
+doing a rebase), failing out in case of an error. If no
+`<versionlist>` is supplied, it defaults to `all`.
 
 ## Marking XSAs as published
 
@@ -410,7 +421,7 @@ Edit the `global.meta` file and remove the stanza for the version no
 longer supported.
 
 (Eventually this will be implemented by the `xsatool global
-end-support [version]` command.)
+end-support <version>` command.)
 
 ## 'Canonicalizing' metadata files
 
diff --git a/main.go b/main.go
index c7890fe4735ecd9b117ce887bac211d56847aacf..b1b3b4846d6c7c0b9e2ea19218e9e54e94f32e71 100644 (file)
--- a/main.go
+++ b/main.go
@@ -47,30 +47,6 @@ func ForEachXenRepo(f func(*XenRepo, Tree) error) error {
        return ForEachCodeTree(f2)
 }
 
-// Convert argument list into a set of versions:
-// - If no versions exist, use SupportedVersions from metadata
-//   - If hasPatches is true, include only versions which have patches; otherwise
-//     include all of them.
-// - Otherwise add the list of versions in order
-func VersionsFromArgs(xsa *XSAMeta, args []string, hasPatches bool) (vers []XenVersion) {
-       if len(args) == 0 || (len(args) == 1 && args[0] == "all") {
-               for _, v := range xsa.SupportedVersions {
-                       // Check to see if the branch exists
-                       if hasPatches && !xsa.HasRecipe(v) {
-                               // FIXME: Should this be "break" instead?
-                               continue
-                       }
-                       vers = append(vers, v)
-               }
-       } else {
-               // FIXME: Verify xenversion format
-               for _, v := range args {
-                       vers = append(vers, XenVersion(v))
-               }
-       }
-       return
-}
-
 type MainFunc func(*XSAMeta, []string) int
 
 // GLOBAL
diff --git a/test.go b/test.go
index d1d085a54164db121f5ca345b90da9a0417113bc..a912452cf74ca71e81532f37846208fd60c6616f 100644 (file)
--- a/test.go
+++ b/test.go
@@ -5,8 +5,15 @@ import (
 )
 
 func test(xsa *XSAMeta, args []string, apply bool, build bool) (ret int) {
-
-       vers := VersionsFromArgs(xsa, args, false)
+       vers := xsa.SupportedVersions
+       if len(args) > 0 {
+               var err error
+               vers, err = VersionsFromString(args[0], xsa.SupportedVersions, nil)
+               if err != nil {
+                       fmt.Printf("Error parsing versions: %v", err)
+                       return
+               }
+       }
 
        for _, v := range vers {
                prefix := "xsa/test"
diff --git a/xsa.go b/xsa.go
index 0392143f8687ddf81178b5c13da03061fcac94dc..d4a8ae2a3c0aa977e5cdaf7020a38012511b379a 100644 (file)
--- a/xsa.go
+++ b/xsa.go
@@ -6,7 +6,15 @@ import (
 )
 
 func sync(xsa *XSAMeta, args []string, sync bool) (ret int) {
-       vers := VersionsFromArgs(xsa, args, true)
+       vers := xsa.SupportedVersions
+       if len(args) > 0 {
+               var err error
+               vers, err = VersionsFromString(args[0], xsa.SupportedVersions, xsa.HasRecipe)
+               if err != nil {
+                       fmt.Printf("Error parsing versions: %v", err)
+                       return
+               }
+       }
 
        if !sync && len(vers) > 1 {
                fmt.Printf("Error: Doesn't make sense to make more than one version\n")
@@ -59,7 +67,16 @@ func MainMakePatches(xsa *XSAMeta, args []string) (ret int) {
 }
 
 func MainSyncBranch(xsa *XSAMeta, args []string) (ret int) {
-       vers := VersionsFromArgs(xsa, args, false)
+       vers := xsa.SupportedVersions
+       if len(args) > 0 {
+               var err error
+               vers, err = VersionsFromString(args[0], xsa.SupportedVersions, nil)
+               if err != nil {
+                       fmt.Printf("Error parsing versions: %v", err)
+                       return
+               }
+       }
+       //vers := VersionsFromArgs(xsa, args, false)
 
        for _, v := range vers {
                prefix := "xsa"
@@ -240,7 +257,16 @@ func MainResetBase(xsa *XSAMeta, args []string) (ret int) {
        //  -- Re-set stableref to upstream
        //  -- Re-apply recipe
 
-       vers := VersionsFromArgs(xsa, args, false)
+       vers := xsa.SupportedVersions
+       if len(args) > 0 {
+               var err error
+               vers, err = VersionsFromString(args[0], xsa.SupportedVersions, nil)
+               if err != nil {
+                       fmt.Printf("Error parsing versions: %v", err)
+                       return
+               }
+       }
+       //vers := VersionsFromArgs(xsa, args, false)
 
        for _, v := range vers {
                r := xsa.GetRecipe(v)