I'm trying to provide completion for positional parameters.
Somewhere I found note that they are not very well supported, but currently I'm not able to find exact place in spec and I'm not sure what that really means.
In meantime I found CompletionCandidatesTest.java in sources which would suggest that they're supported in some fashion or at least prepared to support it.
That's why I would like to know if they work and if yes what I'm doing wrong.
Currently my code in Groovy looks like this:
package com.some.package
import picocli.CommandLine
import picocli.CommandLine.Command
#Command
class TjTest implements Runnable {
static class TjTestCandidates implements Iterable<String> {
#Override
Iterator<String> iterator() {
return Arrays.asList("aaaa", "bbbb", "cccc", "dddd", "eeeee", "ffff").iterator()
}
}
#CommandLine.Option(names = "-x", completionCandidates = TjTestCandidates)
String x;
#CommandLine.Parameters(completionCandidates = TjTestCandidates)
String param;
#Override
public void run() {
println "Start"
println x
println param;
println "Stop"
}
public static void main(String[] args) {
CommandLine.run(new TjTest(), args);
}
}
I performed required bash commands like this:
java -cp "picocli-3.9.5.jar;tj.jar" picocli.AutoComplete -f -n tjtest com.some.package.TjTest
. tjtest_completion
It works like a charm for an option. Unfortunately I was not able to make it work for parameter.
I was also trying to:
remove #Option and leave only #Parameters
put index in parameter
Your code looks fine. The current state (picocli 3.9.5) is that positional parameter completion works in JLine, but not in bash/zsh.
There is an outstanding todo item to fix this. Someone contributed a pull request to address this but it had an issue and has not been merged.
Contributions are welcome!
Related
I'm trying to load values from environment variables when running a BenchmarkDotNet project from the command line. I'm passing my environment variables using --envVars key:value. However, they're not being picked up by the benchmark.
Here's some sample code:
using BenchmarkDotNet.Attributes;
[MemoryDiagnoser]
[ReturnValueValidator(failOnError: true)]
public class RedisBenchmark
{
[GlobalSetup]
public void GlobalSetup()
{
_redisService.Servers = System.Environment.GetEnvironmentVariable(Constants.REDIS_SERVERS) ?? "";
if (string.IsNullOrEmpty(_redisService.Servers)) _redisService.Servers = "NO SERVERS SPECIFIED";
}
private static RedisService _redisService = new();
[Benchmark(Description = "Write and Read to Redis")]
public void WriteAndReadRedis() => _redisService.WriteAndRead();
}
Notice the "NO SERVERS SPECIFIED" string above. When my RedisService runs and outputs its connection string as the benchmark warms up, it outputs that string, so I know that GlobalSetup ran, but that it wasn't able to find or read the environment variable.
Is there something I'm missing?
Some background and discussion here as well:
https://github.com/dotnet/BenchmarkDotNet/issues/2156
As of this writing, there is a bug affecting the [ReturnValueValidator] and it looks like it skips running GlobalSetup. As a temporary fix you can remove the [ReturnValueValidator] and it should work.
I am currently writing a Gradle plugin on Java.
I've successfully written a plugin able to receive String parameters con its configuration. However, I would like to pass instead of the value of the arguments a reference to a function on a gradle file so to execute it for getting the String argument. Is it possible? How should I performe it?
My current code is the following:
public class DemoPluginExtension {
private String commitId = "";
public String getCommitId() {
return commitId;
}
public void setCommitId(String commitId) {
this.commitId = commitId;
}
}
I have a gradle.build file with a code able to extract the commitId, lets call it getGitCommitIdInfo. So, I am able to use the plugin as follows:
demoSetting {
def commitIdfInfo = getGitCommitIdInfo()
commitId = commitIdfInfo
}
What I would like to perform is to use the plugin like follows:
demoSetting {
commitIdfunc = this.&getGitCommitIdInfo
}
But I do not know how to write the DemoPluginExtension code.
Any suggestion is going to be welcomed.
Thanks a lot!
Our school project has us make a game using Processing 3. After some studying with the language, our team is pretty confident we can work with the project, though we do have certain reservations of the chosen language.
However, there is one major question we are wondering and could not find an answer. In C++ and many others, when you create a new class in a new file you also create a header file you can include. Does Processing 3 have something similar? I know you can "include" files by adding more tabs, which is still weird but whatever. We would like to have some sort of declarations in advance so we can comment/describe classes and their methods, rather than force each member go through lots of code to find the proper point.
In short, we want to be able to do something like this:
Example.pde
class Example {
//Description
Example();
//Description
void doSomething(int variable);
}
//Other team members don't have to worry past this,
//as they have already seen the public interface
Example::Example()
{
//Constructor
}
void Example::doSomething(int variable)
{
//Function
}
Or do we have to always to like this:
Example.pde
class Example {
//Description
Example()
{
//Constructor
}
//Description
void doSomething(int variable)
{
//Function
}
}
Processing is written in Java, so you can only do things that Java supports. Java does not support header files, so no, you can't use header files in Processing.
However, it sounds like what you're really looking for is an interface.
interface Example {
void doSomething(int variable);
}
class MyExample implements Example{
public MyExample(){
//Constructor
}
void doSomething(int variable){
//Function
}
}
With this, you would only need to show other team members the interface, not the class. As long as they program to the interface, they don't need to ever see the class implementation.
More info on interfaces can be found in the Processing reference.
This is a bit involved, and I want to explain this succinctly without making you read a lot, then show the code. I'm not good at that.
Barebones explanation. In this assignment, we are learning, how to compile,interpret in comand prompt, create a package, create a class and sub-classes, import the sub-classes, and execute println commands in all the sub-classes as a single compiled program, and display such in command prompt. I'm missing something, and the subclass println commands don't display when I run GreetingsClass.java, the Superclass. They are all in the same package. The package directory is com.cisp2030.course, and the three Chapters class files exist in a .Chapters folder inside of .course.
First, GreetingsClass.java:
package com.cisp2030.course;
import com.cisp2030.course.Chapters.*;
public class GreetingsClass
{
Chapter1 c1 = new Chapter1();
Chapter2 c2 = new Chapter2();
Chapter3 c3 = new Chapter3();
public static void main(String[] args)
{
System.out.println("$ Greetings, CISP2030!");
System.out.println(c1);
}
}
This is supposed to import and instantiate the variables of the next code contained as Chapter1.class in .Chapters folder.
package com.cisp2030.course.Chapters;
public class Chapter1
{
public Chapter1()
{
System.out.println("Hello from Chapter1!");
}
}
Just imagine that the above code is one of three that range from Chapter1-Chapter3, and they have been compiled by Command Prompt into class files in their respective directory.
The expected output of compiling, interpreting, and running this program in command prompt should be one program which displays all 3-4 println commands. However, at this time, running hte command prompt only displays the one println command. I think this is because I need to sub-class the Chapter classes to GreetingsClass, and having them imported already, somehow direct GreetingsClass to execute the commands of hte Chapters class files, but I don't know how, and I've googled this consistently, and searched through my textbook and am none the wiser. I think I'm missing something in the code itself, but I don't know enough to come up with any ideas. Any help or advice would be greatly appreciated.
Code has been finished:
package com.cisp2030.course;
import com.cisp2030.course.Chapters.*;
public class GreetingsClass
{
public static void main(String[] args)
{
System.out.println("$ Greetings, CISP2030!");
Chapter1 c1 = new Chapter1();
Chapter2 c2 = new Chapter2();
Chapter3 c3 = new Chapter3();
}
}
Does that even compile?
Java doesn't allow static constructors.
public Chapter1() // removed "static"
{
System.out.println("Hello from Chapter1!");
}
c1 is a member of GreetingsClass. In main() you are in a static method, not a method of GreetingsClass and so you can't access it's members. Most obvious solution is to add GreetingsClass greetings = new GreetingsClass(); to main and try to get c1 out of that.
Im creating an annotator called "NewAnnotator" and try to make it works in a pipeline with others annotators in ClearTK like:
SentenceAnnotator, PosTaggerAnnotator, etc. So I want to be able to run pipeline:
aggregate.add(SentenceAnnotator.getDescription());
aggregate.add(PosTaggerAnnotator.getDescription());
aggregate.add(NewAnnotator.getDescription());
// run the classification pipeline on the new texts
SimplePipeline.runPipeline(reader, aggregate.createAggregateDescription());
I wrote the code with no error, but when running it returns a lot of errors, which I think from this part in my NewAnnotator code:
public static AnalysisEngineDescription getDescription() throws ResourceInitializationException {
return AnalysisEngineFactory.createPrimitiveDescription(
NewAnnotator.class,
PARAM_POSTAG_MODEL_FILE,
ParamUtil.getParameterValue(PARAM_POSTAG_MODEL_FILE, "/somepath"));
}
public static final String PARAM_POSTAG_MODEL_FILE = ConfigurationParameterFactory.createConfigurationParameterName(
PosTaggerAnnotator.class,
"postagModelFile");
I almost copy this part from PosTaggerAnnotator, but it has no use in my NewAnnotator, I just add in so that I can use:
aggregate.add(NewAnnotator.getDescription());
because I don't know any other way to add to aggregate without .getDescription(); and I also don't know how to declare a correct getDescription() in my annotator, even it can works fine without it.
So please give me some advise here if you have experienced it! Thank you!
getDescription() is a convenience method to create a default description for your annotator. It uses AnalysisEngineFactory.createPrimitiveDescription(), to which you need to provide the right arguments, like this:
public static AnalysisEngineDescription getDescription() throws ResourceInitializationException {
return AnalysisEngineFactory.createPrimitiveDescription(
NewAnnotator.class,
first_parameter_name, first_parameter_value,
second_parameter_name, second_parameter_value,
... );
}
There are more examples in the uimaFIT codebase.