diff --git a/README.md b/README.md index 127cb7f..1ed1b70 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ $ export PATH=$PATH:`pwd`/target/appassembler/bin ```bash $ coop --help USAGE - coop [-hV] [--human-readable] [--reverse-columns] [--show-header] [--verbose] [...] [COMMAND] + coop [-hV] [--human-readable] [--reverse-columns] [--show-header] [--verbose] [--region=] ... [COMMAND] List s3 paths recursively with content sizes. @@ -49,9 +49,10 @@ E.g. PARAMETERS - [...] Zero or more s3 URIs. + ... One or more s3 URIs. OPTIONS + --region= AWS region, default US_WEST_2. --human-readable Format content sizes in binary multi-byte units. --show-header Show column header row in output. --reverse-columns Reverse the order of output columns. diff --git a/src/main/java/com/github/heuermh/cooper/Cooper.java b/src/main/java/com/github/heuermh/cooper/Cooper.java index 2720aea..26a1cad 100644 --- a/src/main/java/com/github/heuermh/cooper/Cooper.java +++ b/src/main/java/com/github/heuermh/cooper/Cooper.java @@ -30,6 +30,7 @@ import picocli.CommandLine.Command; import picocli.CommandLine.HelpCommand; +import picocli.CommandLine.ITypeConverter; import picocli.CommandLine.ScopeType; import software.amazon.awssdk.regions.Region; @@ -63,6 +64,14 @@ ) public final class Cooper implements Callable { + @picocli.CommandLine.Option( + names = { "--region" }, + type = Region.class, + converter = RegionConverter.class, + defaultValue = "US_WEST_2" + ) + private Region region; + @picocli.CommandLine.Option(names = { "--human-readable" }) private boolean humanReadable; @@ -75,7 +84,7 @@ public final class Cooper implements Callable { @picocli.CommandLine.Option(names = { "--verbose" }) private boolean verbose; - @picocli.CommandLine.Parameters(index = "0..*", descriptionKey = "uris") + @picocli.CommandLine.Parameters(index = "0..*", arity = "1..*", descriptionKey = "uris") private List uris; /** Logger. */ @@ -92,7 +101,7 @@ public final class Cooper implements Callable { public Integer call() throws Exception { S3Client s3 = S3Client.builder() - .region(Region.US_WEST_2) + .region(region) .build(); if (showHeader) { diff --git a/src/main/java/com/github/heuermh/cooper/RegionConverter.java b/src/main/java/com/github/heuermh/cooper/RegionConverter.java new file mode 100644 index 0000000..6bdd3ad --- /dev/null +++ b/src/main/java/com/github/heuermh/cooper/RegionConverter.java @@ -0,0 +1,34 @@ +/* + * The authors of this file license it to you under the + * Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You + * may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.github.heuermh.cooper; + +import picocli.CommandLine.ITypeConverter; + +import software.amazon.awssdk.regions.Region; + +/** + * AWS Region converter. + * + * @author Michael Heuer + */ +//@Immutable +final class RegionConverter implements ITypeConverter { + + @Override + public Region convert(final String value) throws Exception { + return Region.of(value); + } +} diff --git a/src/main/resources/com/github/heuermh/cooper/Messages.properties b/src/main/resources/com/github/heuermh/cooper/Messages.properties index 3ae9d0d..2a208e3 100644 --- a/src/main/resources/com/github/heuermh/cooper/Messages.properties +++ b/src/main/resources/com/github/heuermh/cooper/Messages.properties @@ -21,6 +21,7 @@ coop.usage.descriptionHeading = %n human-readable = Format content sizes in binary multi-byte units. show-header = Show column header row in output. +region = AWS region, default US_WEST_2. reverse-columns = Reverse the order of output columns. -uris = Zero or more s3 URIs. +uris = One or more s3 URIs. verbose = Show additional logging messages.