Added region support to CLI - #335
rob-ryszewski wants to merge 6 commits into
Conversation
… written to amp/jwt.json by clerk/clerk.go
| @@ -16,35 +16,30 @@ const fileName = "Ampersand/config.json" | |||
| // IMPORTANT: Do not modify the JSON labels in this struct without ensuring backwards | |||
| // compatibility, since those strings are written to the user's config file on their computer. | |||
There was a problem hiding this comment.
Since this was only Config.Token and not being used anywhere, (token was being managed in amp/jwt.json by clerk/clerk.go, this particular changeset doesn't break any backwards compatibility for this config
483d70b to
18ed5db
Compare
18ed5db to
a6d5183
Compare
| // 1. --region | ||
| // 2. AMP_REGION | ||
| // 3. 'amp set:region' (config/appdata file) | ||
| // 4. region.Default ("us") |
There was a problem hiding this comment.
the explicit priority list
|
|
||
| // Parse normalizes a region name, and checks that it is a well-formed DNS label. | ||
| // It deliberately does not check the name against Known, so that as new regions are supported, | ||
| // users can set them without having to upgrade the build of their CLI. |
There was a problem hiding this comment.
figured this would be preferable to a new region being created and needing to release a new CLI version and users having to update to it (or do the 3 env var export)
a6d5183 to
8e90fc8
Compare
laurenzlong
left a comment
There was a problem hiding this comment.
@rob-ryszewski I'll let @eberle1080 review this for technical accuracy, but can you swap the priority order so that it is:
--regionflagamp set:regionAMP_REGIONenv var
eberle1080
left a comment
There was a problem hiding this comment.
A few minor suggestions but no blockers
| // if no config file exists, that is not an error | ||
| // the caller is returned an empty Config object, and Set() will create the file | ||
| return Config{}, nil //nolint:nilerr |
There was a problem hiding this comment.
Check for the proper error to exclude (e.g.os.IsNotExist(err)) instead of assuming that's what the error is and unconditionally returning nil
There was a problem hiding this comment.
ah, ty! looks like with this particular xdg method, we only get a broad catchall error:
fmt.Errorf("could not locate `%s` in any of the following paths: %v",
filepath.Base(name), searchedPaths)
so ended up switching to xdg.ConfigFile, and doing the os.IsNotExist(err) check after the os.ReadFile(), let me know what you think!
Order changed, and just wanted to confirm with you:
If somebody uses
In short:
|
Added support for (in priority order):
amp set:regionOtherwise defaults to
"us"Example script
The example script:
fresh local build:
basic help messages:
basic get/set, and showing it changes the URLs:
again, but with region regionDoesntExistYet:
with
--region la:with AMP_REGION=ap;
with
AMP_REGIONand--regionboth set: