Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [osgi-users] Specifying required parameter in Gogo command

My last hint would be:
Registring an Converter
https://github.com/apache/felix-dev/blob/master/gogo/runtime/src/main/java/org/apache/felix/service/command/Converter.java

If you found an Solution. please let me know.


On 3/4/21 9:38 PM, Alain Picard wrote:
Stefan,

I tried this, but as it states this is for flags. i.e. "
*If this value is specified, then the command parsing
* will not expect a value on the command line for this parameter.
We use it as such:
@Parameter(names="--config", absentValue="false", presentValue="true") boolean processSysConfig,

but here we expect a value but it is just optional.

Thanks for pointing out that this might be better asked in the Felix foum.

Alain


On Thu, Mar 4, 2021 at 3:25 PM Stefan Bischof <stbischof@xxxxxxxxxxx> wrote:

Hi,

maybe you can do it with the "presentValue"

    /**
     * The default value of the parameter if its name is present on the
     * command line. If this value is specified, then the command parsing
     * will not expect a value on the command line for this parameter.
     * If this value is UNSPECIFIED, then an argument must be specified on the
     * command line for the parameter.
     * @return default value of the parameter if its name is present on the
     *         command line.
    **/
    String presentValue() default UNSPECIFIED;

https://github.com/apache/felix-dev/blob/master/gogo/runtime/src/main/java/org/apache/felix/service/command/Parameter.java

gogo is (sadly) not an osgi spec. so maybe you can get more help in the apache felix user mailing list.

regards



On 3/4/21 9:11 PM, Alain Picard wrote:
Stefan,

Thanks for reaching out. I believe that in order to keep it simple I may have missed showing the real issue.
Here is the command:

@Descriptor("...")
public void createTenantAndUserOnKCBA(
@Parameter(names={"-t", "--tenant"}, absentValue="") @Descriptor(TENANT_DESCR + REQ) String tenantName,
@Parameter(names="-ps", absentValue= "") @Descriptor(PS_DESCR) String psName,
@Parameter(names="-email", absentValue="") @Descriptor(EMAIL_DESCR + REQ) String email,
@Parameter(names="-fname", absentValue="") @Descriptor(FNAME_DESCR + REQ) String firstName,
@Parameter(names="-lname", absentValue="") @Descriptor(LNAME_DESCR + REQ) String lastName,
@Parameter(names="-full", absentValue="") @Descriptor(FULL_NAME_DESCR) String fullName,
@Parameter(names="-pwd", absentValue="") @Descriptor(PASS_DESCR + REQ) String password,
@Parameter(names="-ent", absentValue="") @Descriptor(ENT_DESCR) String enterpriseName) {
//perform command
}

For arguments that are truly required you can see the use of the REQ constant to show that.

I can understand your approach if maybe dealing with a single argument, but here we cleary need the ability to specify absentValue=null or equivalent for some of the parameters, which is where we're struggling to match the specification.

Thanks
Alain





On Thu, Mar 4, 2021 at 2:16 PM Stefan Bischof <stbischof@xxxxxxxxxxx> wrote:

I think this could be done by overloading the method.

@Descriptor("...")
String foo(){
return foo(null);
}

@Descriptor("...")
String foo(@Parameter(names="-ps")String text){

}



On 2/17/21 7:11 PM, Alain Picard wrote:
am trying to specify some required parameters in Gogo but I can't find a way to set absentValue to null (can't just not provide it as it is required).

This won't compile:
@Parameter(names="-ps") @Descriptor(PS_DESCR) String psName,

Example:
@Parameter(names="-ps", absentValue= "") @Descriptor(PS_DESCR) String psName,

results in:
-ps   ProjectSpace name [optional]

Where I want it not to show up as optional.

The code checks for null, otherwise it will add the "[optional]" tag.

Thanks
Alain


_______________________________________________
osgi-users mailing list
osgi-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/osgi-users
_______________________________________________
osgi-users mailing list
osgi-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/osgi-users

_______________________________________________
osgi-users mailing list
osgi-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/osgi-users
_______________________________________________
osgi-users mailing list
osgi-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/osgi-users

_______________________________________________
osgi-users mailing list
osgi-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/osgi-users

Back to the top