Skip to content

Commit

Permalink
add region option, fix uris arity
Browse files Browse the repository at this point in the history
  • Loading branch information
heuermh committed May 28, 2024
1 parent b24f43d commit 21322d3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ export PATH=$PATH:`pwd`/target/appassembler/bin
```bash
$ coop --help
USAGE
coop [-hV] [--human-readable] [--reverse-columns] [--show-header] [--verbose] [<uris>...] [COMMAND]
coop [-hV] [--human-readable] [--reverse-columns] [--show-header] [--verbose] [--region=<region>] <uris>... [COMMAND]

List s3 paths recursively with content sizes.

Expand All @@ -49,9 +49,10 @@ E.g.


PARAMETERS
[<uris>...] Zero or more s3 URIs.
<uris>... One or more s3 URIs.

OPTIONS
--region=<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.
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/github/heuermh/cooper/Cooper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,6 +64,14 @@
)
public final class Cooper implements Callable<Integer> {

@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;

Expand All @@ -75,7 +84,7 @@ public final class Cooper implements Callable<Integer> {
@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<String> uris;

/** Logger. */
Expand All @@ -92,7 +101,7 @@ public final class Cooper implements Callable<Integer> {
public Integer call() throws Exception {

S3Client s3 = S3Client.builder()
.region(Region.US_WEST_2)
.region(region)
.build();

if (showHeader) {
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/github/heuermh/cooper/RegionConverter.java
Original file line number Diff line number Diff line change
@@ -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<Region> {

@Override
public Region convert(final String value) throws Exception {
return Region.of(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 21322d3

Please sign in to comment.