-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add the feature to turn of WRAP for CLI output
- Loading branch information
Showing
10 changed files
with
209 additions
and
54 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
56 changes: 56 additions & 0 deletions
56
ksql-cli/src/main/java/io/confluent/ksql/cli/console/CliConfig.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,56 @@ | ||
/* | ||
* Copyright 2019 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.cli.console; | ||
|
||
import io.confluent.ksql.configdef.ConfigValidators; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.kafka.common.config.AbstractConfig; | ||
import org.apache.kafka.common.config.ConfigDef; | ||
import org.apache.kafka.common.config.ConfigDef.Importance; | ||
import org.apache.kafka.common.config.ConfigDef.Type; | ||
|
||
public class CliConfig extends AbstractConfig { | ||
|
||
public static final String WRAP_CONFIG = "WRAP"; | ||
|
||
private static final ConfigDef CONFIG_DEF = new ConfigDef() | ||
.define( | ||
WRAP_CONFIG, | ||
Type.STRING, | ||
OnOff.ON.name(), | ||
ConfigValidators.enumValues(OnOff.class), | ||
Importance.MEDIUM, | ||
"A value of 'OFF' will clip lines to ensure that query results do not exceed the " | ||
+ "terminal width (i.e. each row will appear on a single line)." | ||
); | ||
|
||
public CliConfig(final Map<?, ?> originals) { | ||
super(CONFIG_DEF, originals); | ||
} | ||
|
||
public CliConfig with(final String property, final Object value) { | ||
final Map<String, Object> originals = new HashMap<>(originals()); | ||
originals.put(property, value); | ||
return new CliConfig(originals); | ||
} | ||
|
||
@SuppressWarnings("unused") // used in validation | ||
public enum OnOff { | ||
ON, OFF | ||
} | ||
|
||
} |
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
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
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
58 changes: 58 additions & 0 deletions
58
ksql-cli/src/main/java/io/confluent/ksql/cli/console/cmd/SetCliProperty.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,58 @@ | ||
/* | ||
* Copyright 2019 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.cli.console.cmd; | ||
|
||
import java.io.PrintWriter; | ||
import java.util.List; | ||
import java.util.function.BiConsumer; | ||
|
||
final class SetCliProperty implements CliSpecificCommand { | ||
|
||
private static final String HELP = "set <property> <value>:" + System.lineSeparator() | ||
+ "\tSets a CLI local property. NOTE that this differs from setting a KSQL " | ||
+ "property with 'SET property=value' in that it does not affect the server."; | ||
|
||
private final BiConsumer<String, String> setProperty; | ||
|
||
public static SetCliProperty create(final BiConsumer<String, String> setProperty) { | ||
return new SetCliProperty(setProperty); | ||
} | ||
|
||
private SetCliProperty(final BiConsumer<String, String> setProperty) { | ||
this.setProperty = setProperty; | ||
} | ||
|
||
@Override | ||
public boolean matches(final String command) { | ||
return command.toLowerCase().startsWith(getName().toLowerCase()) && !command.contains("="); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "set"; | ||
} | ||
|
||
@Override | ||
public String getHelpMessage() { | ||
return HELP; | ||
} | ||
|
||
@Override | ||
public void execute(final List<String> args, final PrintWriter terminal) { | ||
CliCmdUtil.ensureArgCountBounds(args, 2, 2, getHelpMessage()); | ||
setProperty.accept(args.get(0), args.get(1)); | ||
} | ||
} |
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
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
Oops, something went wrong.