forked from smithy-lang/smithy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
153 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ts/src/main/resources/META-INF/services/software.amazon.smithy.model.validation.Validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
software.amazon.smithy.aws.iam.traits.ConditionKeysValidator | ||
software.amazon.smithy.aws.iam.traits.IamResourceTraitValidator | ||
software.amazon.smithy.aws.iam.traits.IamResourceTraitValidator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
#REPO=ssh://git.amazon.com/pkg/Smithy-Examples | ||
#TEMPLATE_PATH=templates/common-shapes | ||
|
||
REPO=$1 | ||
TEMPLATE=$2 | ||
TEMPLATE_PATH="templates/$TEMPLATE" | ||
RELATIVE_PREFIX=../ | ||
|
||
# Check whether current directory is a Git repo | ||
if git rev-parse --is-inside-work-tree >& /dev/null; then | ||
printf '%s\n' "Cannot clone template into an existing Git repository" >&2 | ||
exit 1 | ||
fi | ||
|
||
rm -rf Smithy-Examples | ||
git clone --filter=blob:none --no-checkout --depth 1 --sparse $REPO | ||
cd Smithy-Examples | ||
git sparse-checkout set --no-cone $TEMPLATE_PATH | ||
git checkout | ||
|
||
SYMLINK_PATH=$(readlink $TEMPLATE_PATH) | ||
if [ -z ${SYMLINK_PATH+x} ]; then | ||
echo "no symlink found. continuing"; | ||
else | ||
echo "symlink found: '$SYMLINK_PATH'"; | ||
TEMPLATE_PATH=${SYMLINK_PATH#$RELATIVE_PREFIX} | ||
git sparse-checkout set --no-cone $TEMPLATE_PATH | ||
git checkout | ||
fi | ||
|
||
rm -rf "../$TEMPLATE" | ||
mv $TEMPLATE_PATH "../$TEMPLATE" | ||
rm -rf ../Smithy-Examples |
112 changes: 112 additions & 0 deletions
112
smithy-cli/src/main/java/software/amazon/smithy/cli/commands/InitCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.smithy.cli.commands; | ||
|
||
import software.amazon.smithy.cli.ArgumentReceiver; | ||
import software.amazon.smithy.cli.Arguments; | ||
import software.amazon.smithy.cli.Command; | ||
import software.amazon.smithy.cli.HelpPrinter; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.function.Consumer; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class InitCommand implements Command { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(InitCommand.class.getName()); | ||
|
||
private final String parentCommandName; | ||
|
||
public InitCommand(String parentCommandName) { | ||
this.parentCommandName = parentCommandName; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "init"; | ||
} | ||
|
||
@Override | ||
public String getSummary() { | ||
return "Init a smithy workspace by template"; | ||
} | ||
|
||
@Override | ||
public int execute(Arguments arguments, Env env) { | ||
arguments.addReceiver(new Options()); | ||
CommandAction action = HelpActionWrapper.fromCommand(this, parentCommandName, this::run); | ||
return action.apply(arguments, env); | ||
} | ||
|
||
public void executeScript(String repoUrl, String template) throws IOException, InterruptedException { | ||
String command = String.format("sh /Volumes/workplace/smithy/smithy-cli/clone-template.sh %s %s", repoUrl, template); | ||
Process p = Runtime.getRuntime().exec(command); | ||
p.waitFor(); | ||
|
||
BufferedReader errorReader = new BufferedReader(new InputStreamReader(p.getErrorStream())); | ||
|
||
String line = ""; | ||
while ((line = errorReader.readLine()) != null) { | ||
LOGGER.log(Level.INFO, line); | ||
} | ||
} | ||
|
||
private int run(Arguments arguments, Env env) { | ||
Options options = arguments.getReceiver(Options.class); | ||
try { | ||
this.executeScript(options.repoUrl, options.template); | ||
} catch (IOException | InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
private static final class Options implements ArgumentReceiver { | ||
private String template; | ||
|
||
private String repoUrl = "ssh://git.amazon.com/pkg/Smithy-Examples"; | ||
|
||
@Override | ||
public boolean testOption(String name) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Consumer<String> testParameter(String name) { | ||
switch (name) { | ||
case "--template": | ||
return value -> template = value; | ||
case "--url": | ||
return value -> repoUrl = value; | ||
default: | ||
return value -> { | ||
}; | ||
} | ||
} | ||
|
||
@Override | ||
public void registerHelp(HelpPrinter printer) { | ||
printer.param("--template", null, "", | ||
"template name"); | ||
printer.param("--url", null, "", | ||
"repo url"); | ||
} | ||
} | ||
} |