Skip to content

Commit 709e1c2

Browse files
Adds a -debug flag to the push and pull commands, to help with debugging why requests fail.
1 parent 8b014b9 commit 709e1c2

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/main/java/com/structurizr/cli/AbstractCommand.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
1414
import org.apache.hc.client5.http.impl.classic.HttpClients;
1515
import org.apache.hc.core5.http.io.entity.EntityUtils;
16+
import org.apache.logging.log4j.Level;
17+
import org.apache.logging.log4j.core.config.Configurator;
18+
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
19+
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
20+
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
21+
import org.apache.logging.log4j.core.layout.PatternLayout;
1622

1723
import java.io.File;
1824
import java.net.URL;
@@ -140,4 +146,23 @@ protected Class loadClass(String fqn, File workspaceFile) throws Exception {
140146
return childClassLoader.loadClass(fqn);
141147
}
142148

149+
protected void configureDebugLogging() {
150+
ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
151+
152+
builder.add(
153+
builder.newAppender("stdout", "Console")
154+
.add(
155+
builder.newLayout(PatternLayout.class.getSimpleName())
156+
.addAttribute(
157+
"pattern",
158+
"%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"
159+
)
160+
)
161+
);
162+
163+
builder.add(builder.newLogger("com.structurizr", Level.DEBUG));
164+
165+
Configurator.reconfigure(builder.build());
166+
}
167+
143168
}

src/main/java/com/structurizr/cli/PullCommand.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public void run(String... args) throws Exception {
4545
option.setRequired(false);
4646
options.addOption(option);
4747

48+
option = new Option("debug", "debug", false, "Enable debug logging");
49+
option.setRequired(false);
50+
options.addOption(option);
51+
4852
CommandLineParser commandLineParser = new DefaultParser();
4953
HelpFormatter formatter = new HelpFormatter();
5054

@@ -54,6 +58,7 @@ public void run(String... args) throws Exception {
5458
String apiSecret = "";
5559
String branch = "";
5660
String passphrase = "";
61+
boolean debug = false;
5762

5863
try {
5964
CommandLine cmd = commandLineParser.parse(options, args);
@@ -64,13 +69,18 @@ public void run(String... args) throws Exception {
6469
apiSecret = cmd.getOptionValue("apiSecret");
6570
branch = cmd.getOptionValue("branch");
6671
passphrase = cmd.getOptionValue("passphrase");
72+
debug = cmd.hasOption("debug");
6773
} catch (ParseException e) {
6874
log.error(e.getMessage());
6975
formatter.printHelp("pull", options);
7076

7177
System.exit(1);
7278
}
7379

80+
if (debug) {
81+
configureDebugLogging();
82+
}
83+
7484
File file;
7585
if (StringUtils.isNullOrEmpty(branch)) {
7686
log.info("Pulling workspace " + workspaceId + " from " + apiUrl);

src/main/java/com/structurizr/cli/PushCommand.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public void run(String... args) throws Exception {
5656
option.setRequired(false);
5757
options.addOption(option);
5858

59+
option = new Option("debug", "debug", false, "Enable debug logging");
60+
option.setRequired(false);
61+
options.addOption(option);
62+
5963
CommandLineParser commandLineParser = new DefaultParser();
6064
HelpFormatter formatter = new HelpFormatter();
6165

@@ -68,6 +72,7 @@ public void run(String... args) throws Exception {
6872
String passphrase = "";
6973
boolean mergeFromRemote = true;
7074
boolean archive = true;
75+
boolean debug = false;
7176

7277
try {
7378
CommandLine cmd = commandLineParser.parse(options, args);
@@ -81,6 +86,7 @@ public void run(String... args) throws Exception {
8186
passphrase = cmd.getOptionValue("passphrase");
8287
mergeFromRemote = Boolean.parseBoolean(cmd.getOptionValue("merge", "true"));
8388
archive = Boolean.parseBoolean(cmd.getOptionValue("archive", "true"));
89+
debug = cmd.hasOption("debug");
8490

8591
if (StringUtils.isNullOrEmpty(workspacePath)) {
8692
log.error("-workspace must be specified");
@@ -93,6 +99,10 @@ public void run(String... args) throws Exception {
9399
System.exit(1);
94100
}
95101

102+
if (debug) {
103+
configureDebugLogging();
104+
}
105+
96106
if (StringUtils.isNullOrEmpty(branch)) {
97107
log.info("Pushing workspace " + workspaceId + " to " + apiUrl);
98108
} else {

0 commit comments

Comments
 (0)