You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apex.apache.org by ra...@apache.org on 2017/02/07 14:06:02 UTC
[1/2] apex-core git commit: APEXCORE-558 Change yellow to bold as the
highlight format for displaying command strings in help output
Repository: apex-core
Updated Branches:
refs/heads/master f04e07c03 -> f9101d9d2
APEXCORE-558 Change yellow to bold as the highlight format for displaying command strings in help output
Project: http://git-wip-us.apache.org/repos/asf/apex-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/apex-core/commit/c68c7f63
Tree: http://git-wip-us.apache.org/repos/asf/apex-core/tree/c68c7f63
Diff: http://git-wip-us.apache.org/repos/asf/apex-core/diff/c68c7f63
Branch: refs/heads/master
Commit: c68c7f636deca865dbc784d60cff5ec9946eae87
Parents: c97dd7c
Author: Sanjay Pujare <sa...@datatorrent.com>
Authored: Fri Dec 2 14:17:24 2016 -0800
Committer: Sanjay Pujare <sa...@Sanjay-DT-Mac2.local>
Committed: Mon Feb 6 12:14:43 2017 -0800
----------------------------------------------------------------------
.../java/com/datatorrent/stram/cli/ApexCli.java | 42 ++++++++---
.../datatorrent/stram/cli/ApexCliMiscTest.java | 73 ++++++++++++++++++++
2 files changed, 107 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/apex-core/blob/c68c7f63/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java
----------------------------------------------------------------------
diff --git a/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java b/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java
index 8a3ea9e..10b294f 100644
--- a/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java
+++ b/engine/src/main/java/com/datatorrent/stram/cli/ApexCli.java
@@ -152,7 +152,19 @@ import sun.misc.SignalHandler;
public class ApexCli
{
private static final Logger LOG = LoggerFactory.getLogger(ApexCli.class);
- private Configuration conf;
+ private static String CONFIG_EXCLUSIVE = "exclusive";
+ private static String CONFIG_INCLUSIVE = "inclusive";
+
+ private static final String COLOR_RED = "\033[38;5;196m";
+ private static final String COLOR_YELLOW = "\033[0;93m";
+ private static final String FORMAT_BOLD = "\033[1m";
+
+ private static final String COLOR_RESET = "\033[0m";
+ private static final String ITALICS = "\033[3m";
+ private static final String APEX_HIGHLIGHT_COLOR_PROPERTY_NAME = "apex.cli.color.highlight";
+ private static final String APEX_HIGHLIGHT_COLOR_ENV_VAR_NAME = "APEX_HIGHLIGHT_COLOR";
+
+ protected Configuration conf;
private FileSystem fs;
private StramAgent stramAgent;
private final YarnClient yarnClient = YarnClient.createYarnClient();
@@ -184,9 +196,7 @@ public class ApexCli
private String forcePrompt;
private String kerberosPrincipal;
private String kerberosKeyTab;
-
- private static String CONFIG_EXCLUSIVE = "exclusive";
- private static String CONFIG_INCLUSIVE = "inclusive";
+ private String highlightColor = null;
private static class FileLineReader extends ConsoleReader
{
@@ -1153,6 +1163,22 @@ public class ApexCli
}
}
+ /**
+ * get highlight color based on env variable first and then config
+ *
+ */
+ protected String getHighlightColor()
+ {
+ if (highlightColor == null) {
+ highlightColor = System.getenv(APEX_HIGHLIGHT_COLOR_ENV_VAR_NAME);
+ if (StringUtils.isBlank(highlightColor)) {
+ highlightColor = conf.get(APEX_HIGHLIGHT_COLOR_PROPERTY_NAME, FORMAT_BOLD);
+ }
+ highlightColor = highlightColor.replace("\\e", "\033");
+ }
+ return highlightColor;
+ }
+
public void init() throws IOException
{
conf = StramClientUtils.addDTSiteResources(new YarnConfiguration());
@@ -1532,9 +1558,9 @@ public class ApexCli
private void printHelp(String command, CommandSpec commandSpec, PrintStream os)
{
if (consolePresent) {
- os.print("\033[0;93m");
+ os.print(getHighlightColor());
os.print(command);
- os.print("\033[0m");
+ os.print(COLOR_RESET);
} else {
os.print(command);
}
@@ -1547,7 +1573,7 @@ public class ApexCli
if (commandSpec.requiredArgs != null) {
for (Arg arg : commandSpec.requiredArgs) {
if (consolePresent) {
- os.print(" \033[3m" + arg + "\033[0m");
+ os.print(" " + ITALICS + arg + COLOR_RESET);
} else {
os.print(" <" + arg + ">");
}
@@ -1556,7 +1582,7 @@ public class ApexCli
if (commandSpec.optionalArgs != null) {
for (Arg arg : commandSpec.optionalArgs) {
if (consolePresent) {
- os.print(" [\033[3m" + arg + "\033[0m");
+ os.print(" [" + ITALICS + arg + COLOR_RESET);
} else {
os.print(" [<" + arg + ">");
}
http://git-wip-us.apache.org/repos/asf/apex-core/blob/c68c7f63/engine/src/test/java/com/datatorrent/stram/cli/ApexCliMiscTest.java
----------------------------------------------------------------------
diff --git a/engine/src/test/java/com/datatorrent/stram/cli/ApexCliMiscTest.java b/engine/src/test/java/com/datatorrent/stram/cli/ApexCliMiscTest.java
new file mode 100644
index 0000000..f6b7277
--- /dev/null
+++ b/engine/src/test/java/com/datatorrent/stram/cli/ApexCliMiscTest.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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.datatorrent.stram.cli;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ *
+ */
+public class ApexCliMiscTest
+{
+ ApexCli cli;
+
+ static Map<String, String> env = new HashMap<String, String>();
+ static String userHome;
+
+ @Before
+ public void startingTest()
+ {
+ try {
+
+ cli = new ApexCli();
+ cli.init();
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @After
+ public void finishedTest()
+ {
+ cli = null;
+ }
+
+ @Test
+ public void testGetHighlightColorDefault() throws Exception
+ {
+ cli.conf.clear();
+ Assert.assertEquals("\033[1m", cli.getHighlightColor());
+ }
+
+ @Test
+ public void testGetHighlightColorFromConf() throws Exception
+ {
+ cli.conf.clear();
+ cli.conf.set("apex.cli.color.highlight", "\033[0;93m");
+ Assert.assertEquals("\033[0;93m", cli.getHighlightColor());
+ }
+}
[2/2] apex-core git commit: Merge branch 'APEXCORE-558.sanjay' of
https://github.com/sanjaypujare/apex-core
Posted by ra...@apache.org.
Merge branch 'APEXCORE-558.sanjay' of https://github.com/sanjaypujare/apex-core
Project: http://git-wip-us.apache.org/repos/asf/apex-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/apex-core/commit/f9101d9d
Tree: http://git-wip-us.apache.org/repos/asf/apex-core/tree/f9101d9d
Diff: http://git-wip-us.apache.org/repos/asf/apex-core/diff/f9101d9d
Branch: refs/heads/master
Commit: f9101d9d23e502920bed1c2a4d20b5ed0c045301
Parents: f04e07c c68c7f6
Author: Munagala V. Ramanath <ra...@datatorrent.com>
Authored: Tue Feb 7 06:03:56 2017 -0800
Committer: Munagala V. Ramanath <ra...@datatorrent.com>
Committed: Tue Feb 7 06:03:56 2017 -0800
----------------------------------------------------------------------
.../java/com/datatorrent/stram/cli/ApexCli.java | 42 ++++++++---
.../datatorrent/stram/cli/ApexCliMiscTest.java | 73 ++++++++++++++++++++
2 files changed, 107 insertions(+), 8 deletions(-)
----------------------------------------------------------------------