You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-commits@incubator.apache.org by "Archie Cobbs (JIRA)" <ji...@apache.org> on 2007/04/25 16:55:15 UTC

[jira] Created: (IVY-480) Allow "main" parameters to be passed directly (instead of using -args flag)

Allow "main" parameters to be passed directly (instead of using -args flag)
---------------------------------------------------------------------------

                 Key: IVY-480
                 URL: https://issues.apache.org/jira/browse/IVY-480
             Project: Ivy
          Issue Type: Improvement
          Components: Core
    Affects Versions: 1.4.1
            Reporter: Archie Cobbs


When running ivy in standalone mode using the {{-main}} flag, any extra parameters passed on the command line (i.e., not as flag arguments) are simply ignored.

E.g., if I invoke {{java fr.jayasoft.ivy.Main -main com.exmaple.Main foo bar}} the {{foo bar}} parameters are ignored. To pass "foo" and "bar" to my main method, I have to use {{-args foo}} and {{-args bar}}.

Suggestion: when using the {{-main}} flag, allow the parameters to the main method to be passed directly on the command line as "extra" parameters, as an alternative to using the {{-args}} flag.

The motivation for this is that this would be much easier to deal with in shell scripts. E.g. suppose I want to write a shell script {{/usr/bin/foo}} which uses ivy to resolve dependencies and execute some main class {{com.example.foo.Main}}. To do this I'd have to parse the command line into individual arguments, then precatenate each one with a {{-args}} flag, etc. This sounds hard enough, but when you consider that some parameters may be quoted, it becomes nearly impossible. With the change suggested here, it would become trivial: I'd just do something like {{ivy -ivy /usr/share/foo.ivy -main com.example.foo.Main ${1+"$@"} }} in the shell script.

If this is implemented, it should probably become the recommended approach, and {{-args}} be deprecated.

As a side note, the {{-args}} flag is mis-named: it should be called {{-arg}} instead (but I'd prefer to have it just be deprecated).


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (IVY-480) Allow "main" parameters to be passed directly (instead of using -args flag)

Posted by "Archie Cobbs (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IVY-480?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Archie Cobbs updated IVY-480:
-----------------------------

    Attachment: argspatch.txt

Attaching an (untested) patch to implement this improvement.


> Allow "main" parameters to be passed directly (instead of using -args flag)
> ---------------------------------------------------------------------------
>
>                 Key: IVY-480
>                 URL: https://issues.apache.org/jira/browse/IVY-480
>             Project: Ivy
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 1.4.1
>            Reporter: Archie Cobbs
>         Attachments: argspatch.txt
>
>
> When running ivy in standalone mode using the {{-main}} flag, any extra parameters passed on the command line (i.e., not as flag arguments) are simply ignored.
> E.g., if I invoke {{java fr.jayasoft.ivy.Main -main com.exmaple.Main foo bar}} the {{foo bar}} parameters are ignored. To pass "foo" and "bar" to my main method, I have to use {{-args foo}} and {{-args bar}}.
> Suggestion: when using the {{-main}} flag, allow the parameters to the main method to be passed directly on the command line as "extra" parameters, as an alternative to using the {{-args}} flag.
> The motivation for this is that this would be much easier to deal with in shell scripts. E.g. suppose I want to write a shell script {{/usr/bin/foo}} which uses ivy to resolve dependencies and execute some main class {{com.example.foo.Main}}. To do this I'd have to parse the command line into individual arguments, then precatenate each one with a {{-args}} flag, etc. This sounds hard enough, but when you consider that some parameters may be quoted, it becomes nearly impossible. With the change suggested here, it would become trivial: I'd just do something like {{ivy -ivy /usr/share/foo.ivy -main com.example.foo.Main ${1+"$@"} }} in the shell script.
> If this is implemented, it should probably become the recommended approach, and {{-args}} be deprecated.
> As a side note, the {{-args}} flag is mis-named: it should be called {{-arg}} instead (but I'd prefer to have it just be deprecated).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (IVY-480) Allow "main" parameters to be passed directly (instead of using -args flag)

Posted by "Archie Cobbs (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IVY-480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12491722 ] 

Archie Cobbs commented on IVY-480:
----------------------------------

The "--" option terminates option processing.

Example: compile this program:

{noformat}
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;

class xx {

    private static Options getOptions() {
        Option conf = OptionBuilder.withArgName( "conf" )
            .hasArg()
            .withDescription(  "specify configuration" )
            .create( "conf" );
        Options options = new Options();
        options.addOption(conf);
        return options;
    }

    public static void main(String[] args) throws Exception {
        Options options = getOptions();
        GnuParser parser = new GnuParser();
        CommandLine line = parser.parse( options, args );
        String[] extra = line.getArgs();
        System.out.println("there are " + extra.length + " extra args:");
        for (int i = 0; i < extra.length; i++)
            System.out.println("["+i+"] = \"" + extra[i] + "\"");
    }
}
{noformat}

Now run it:

{noformat}
$ java xx -conf asdf -- foo -conf bar
there are 3 extra args:
[0] = "foo"
[1] = "-conf"
[2] = "bar"
{noformat}



> Allow "main" parameters to be passed directly (instead of using -args flag)
> ---------------------------------------------------------------------------
>
>                 Key: IVY-480
>                 URL: https://issues.apache.org/jira/browse/IVY-480
>             Project: Ivy
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 1.4.1
>            Reporter: Archie Cobbs
>         Attachments: argspatch.txt
>
>
> When running ivy in standalone mode using the {{-main}} flag, any extra parameters passed on the command line (i.e., not as flag arguments) are simply ignored.
> E.g., if I invoke {{java fr.jayasoft.ivy.Main -main com.exmaple.Main foo bar}} the {{foo bar}} parameters are ignored. To pass "foo" and "bar" to my main method, I have to use {{-args foo}} and {{-args bar}}.
> Suggestion: when using the {{-main}} flag, allow the parameters to the main method to be passed directly on the command line as "extra" parameters, as an alternative to using the {{-args}} flag.
> The motivation for this is that this would be much easier to deal with in shell scripts. E.g. suppose I want to write a shell script {{/usr/bin/foo}} which uses ivy to resolve dependencies and execute some main class {{com.example.foo.Main}}. To do this I'd have to parse the command line into individual arguments, then precatenate each one with a {{-args}} flag, etc. This sounds hard enough, but when you consider that some parameters may be quoted, it becomes nearly impossible. With the change suggested here, it would become trivial: I'd just do something like {{ivy -ivy /usr/share/foo.ivy -main com.example.foo.Main ${1+"$@"} }} in the shell script.
> If this is implemented, it should probably become the recommended approach, and {{-args}} be deprecated.
> As a side note, the {{-args}} flag is mis-named: it should be called {{-arg}} instead (but I'd prefer to have it just be deprecated).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (IVY-480) Allow "main" parameters to be passed directly (instead of using -args flag)

Posted by "Xavier Hanin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IVY-480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12491704 ] 

Xavier Hanin commented on IVY-480:
----------------------------------

I think you can put as many arguments as you want after the {{-args}} (eg {{java fr.jayasoft.ivy.Main -main com.exmaple.Main -args foo bar}}), which makes it already pretty easy to use with shell scripts and justify the naming. 

Could you confirm if it works for you, and tell if you still think deprecating {{-args}} would be better?

> Allow "main" parameters to be passed directly (instead of using -args flag)
> ---------------------------------------------------------------------------
>
>                 Key: IVY-480
>                 URL: https://issues.apache.org/jira/browse/IVY-480
>             Project: Ivy
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 1.4.1
>            Reporter: Archie Cobbs
>
> When running ivy in standalone mode using the {{-main}} flag, any extra parameters passed on the command line (i.e., not as flag arguments) are simply ignored.
> E.g., if I invoke {{java fr.jayasoft.ivy.Main -main com.exmaple.Main foo bar}} the {{foo bar}} parameters are ignored. To pass "foo" and "bar" to my main method, I have to use {{-args foo}} and {{-args bar}}.
> Suggestion: when using the {{-main}} flag, allow the parameters to the main method to be passed directly on the command line as "extra" parameters, as an alternative to using the {{-args}} flag.
> The motivation for this is that this would be much easier to deal with in shell scripts. E.g. suppose I want to write a shell script {{/usr/bin/foo}} which uses ivy to resolve dependencies and execute some main class {{com.example.foo.Main}}. To do this I'd have to parse the command line into individual arguments, then precatenate each one with a {{-args}} flag, etc. This sounds hard enough, but when you consider that some parameters may be quoted, it becomes nearly impossible. With the change suggested here, it would become trivial: I'd just do something like {{ivy -ivy /usr/share/foo.ivy -main com.example.foo.Main ${1+"$@"} }} in the shell script.
> If this is implemented, it should probably become the recommended approach, and {{-args}} be deprecated.
> As a side note, the {{-args}} flag is mis-named: it should be called {{-arg}} instead (but I'd prefer to have it just be deprecated).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (IVY-480) Allow "main" parameters to be passed directly (instead of using -args flag)

Posted by "Archie Cobbs (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IVY-480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12491710 ] 

Archie Cobbs commented on IVY-480:
----------------------------------

That doesn't work.. what if one of the parameters going to the main class is "-conf," or something else that matches an ivy flag?


> Allow "main" parameters to be passed directly (instead of using -args flag)
> ---------------------------------------------------------------------------
>
>                 Key: IVY-480
>                 URL: https://issues.apache.org/jira/browse/IVY-480
>             Project: Ivy
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 1.4.1
>            Reporter: Archie Cobbs
>         Attachments: argspatch.txt
>
>
> When running ivy in standalone mode using the {{-main}} flag, any extra parameters passed on the command line (i.e., not as flag arguments) are simply ignored.
> E.g., if I invoke {{java fr.jayasoft.ivy.Main -main com.exmaple.Main foo bar}} the {{foo bar}} parameters are ignored. To pass "foo" and "bar" to my main method, I have to use {{-args foo}} and {{-args bar}}.
> Suggestion: when using the {{-main}} flag, allow the parameters to the main method to be passed directly on the command line as "extra" parameters, as an alternative to using the {{-args}} flag.
> The motivation for this is that this would be much easier to deal with in shell scripts. E.g. suppose I want to write a shell script {{/usr/bin/foo}} which uses ivy to resolve dependencies and execute some main class {{com.example.foo.Main}}. To do this I'd have to parse the command line into individual arguments, then precatenate each one with a {{-args}} flag, etc. This sounds hard enough, but when you consider that some parameters may be quoted, it becomes nearly impossible. With the change suggested here, it would become trivial: I'd just do something like {{ivy -ivy /usr/share/foo.ivy -main com.example.foo.Main ${1+"$@"} }} in the shell script.
> If this is implemented, it should probably become the recommended approach, and {{-args}} be deprecated.
> As a side note, the {{-args}} flag is mis-named: it should be called {{-arg}} instead (but I'd prefer to have it just be deprecated).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (IVY-480) Allow "main" parameters to be passed directly (instead of using -args flag)

Posted by "Xavier Hanin (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IVY-480?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Xavier Hanin updated IVY-480:
-----------------------------

    Fix Version/s:     (was: 2.0)
                   2.0.0-alpha-2

> Allow "main" parameters to be passed directly (instead of using -args flag)
> ---------------------------------------------------------------------------
>
>                 Key: IVY-480
>                 URL: https://issues.apache.org/jira/browse/IVY-480
>             Project: Ivy
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 1.4.1
>            Reporter: Archie Cobbs
>             Fix For: 2.0.0-alpha-2
>
>         Attachments: argspatch.txt
>
>
> When running ivy in standalone mode using the {{-main}} flag, any extra parameters passed on the command line (i.e., not as flag arguments) are simply ignored.
> E.g., if I invoke {{java fr.jayasoft.ivy.Main -main com.exmaple.Main foo bar}} the {{foo bar}} parameters are ignored. To pass "foo" and "bar" to my main method, I have to use {{-args foo}} and {{-args bar}}.
> Suggestion: when using the {{-main}} flag, allow the parameters to the main method to be passed directly on the command line as "extra" parameters, as an alternative to using the {{-args}} flag.
> The motivation for this is that this would be much easier to deal with in shell scripts. E.g. suppose I want to write a shell script {{/usr/bin/foo}} which uses ivy to resolve dependencies and execute some main class {{com.example.foo.Main}}. To do this I'd have to parse the command line into individual arguments, then precatenate each one with a {{-args}} flag, etc. This sounds hard enough, but when you consider that some parameters may be quoted, it becomes nearly impossible. With the change suggested here, it would become trivial: I'd just do something like {{ivy -ivy /usr/share/foo.ivy -main com.example.foo.Main ${1+"$@"} }} in the shell script.
> If this is implemented, it should probably become the recommended approach, and {{-args}} be deprecated.
> As a side note, the {{-args}} flag is mis-named: it should be called {{-arg}} instead (but I'd prefer to have it just be deprecated).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (IVY-480) Allow "main" parameters to be passed directly (instead of using -args flag)

Posted by "Xavier Hanin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IVY-480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12491713 ] 

Xavier Hanin commented on IVY-480:
----------------------------------

For arguments matching Ivy command line arguments, I think the problem is the same whatever the solution you choose. At least as long as we use commons-cli. Or maybe there's an option in commons cli to take everything after an argument?

> Allow "main" parameters to be passed directly (instead of using -args flag)
> ---------------------------------------------------------------------------
>
>                 Key: IVY-480
>                 URL: https://issues.apache.org/jira/browse/IVY-480
>             Project: Ivy
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 1.4.1
>            Reporter: Archie Cobbs
>         Attachments: argspatch.txt
>
>
> When running ivy in standalone mode using the {{-main}} flag, any extra parameters passed on the command line (i.e., not as flag arguments) are simply ignored.
> E.g., if I invoke {{java fr.jayasoft.ivy.Main -main com.exmaple.Main foo bar}} the {{foo bar}} parameters are ignored. To pass "foo" and "bar" to my main method, I have to use {{-args foo}} and {{-args bar}}.
> Suggestion: when using the {{-main}} flag, allow the parameters to the main method to be passed directly on the command line as "extra" parameters, as an alternative to using the {{-args}} flag.
> The motivation for this is that this would be much easier to deal with in shell scripts. E.g. suppose I want to write a shell script {{/usr/bin/foo}} which uses ivy to resolve dependencies and execute some main class {{com.example.foo.Main}}. To do this I'd have to parse the command line into individual arguments, then precatenate each one with a {{-args}} flag, etc. This sounds hard enough, but when you consider that some parameters may be quoted, it becomes nearly impossible. With the change suggested here, it would become trivial: I'd just do something like {{ivy -ivy /usr/share/foo.ivy -main com.example.foo.Main ${1+"$@"} }} in the shell script.
> If this is implemented, it should probably become the recommended approach, and {{-args}} be deprecated.
> As a side note, the {{-args}} flag is mis-named: it should be called {{-arg}} instead (but I'd prefer to have it just be deprecated).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (IVY-480) Allow "main" parameters to be passed directly (instead of using -args flag)

Posted by "Xavier Hanin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IVY-480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12491723 ] 

Xavier Hanin commented on IVY-480:
----------------------------------

OK, so now I better understand your patch and your point.

So I agree it would be better to do things like you suggest.

Thanks for your contribution!

> Allow "main" parameters to be passed directly (instead of using -args flag)
> ---------------------------------------------------------------------------
>
>                 Key: IVY-480
>                 URL: https://issues.apache.org/jira/browse/IVY-480
>             Project: Ivy
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 1.4.1
>            Reporter: Archie Cobbs
>         Attachments: argspatch.txt
>
>
> When running ivy in standalone mode using the {{-main}} flag, any extra parameters passed on the command line (i.e., not as flag arguments) are simply ignored.
> E.g., if I invoke {{java fr.jayasoft.ivy.Main -main com.exmaple.Main foo bar}} the {{foo bar}} parameters are ignored. To pass "foo" and "bar" to my main method, I have to use {{-args foo}} and {{-args bar}}.
> Suggestion: when using the {{-main}} flag, allow the parameters to the main method to be passed directly on the command line as "extra" parameters, as an alternative to using the {{-args}} flag.
> The motivation for this is that this would be much easier to deal with in shell scripts. E.g. suppose I want to write a shell script {{/usr/bin/foo}} which uses ivy to resolve dependencies and execute some main class {{com.example.foo.Main}}. To do this I'd have to parse the command line into individual arguments, then precatenate each one with a {{-args}} flag, etc. This sounds hard enough, but when you consider that some parameters may be quoted, it becomes nearly impossible. With the change suggested here, it would become trivial: I'd just do something like {{ivy -ivy /usr/share/foo.ivy -main com.example.foo.Main ${1+"$@"} }} in the shell script.
> If this is implemented, it should probably become the recommended approach, and {{-args}} be deprecated.
> As a side note, the {{-args}} flag is mis-named: it should be called {{-arg}} instead (but I'd prefer to have it just be deprecated).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (IVY-480) Allow "main" parameters to be passed directly (instead of using -args flag)

Posted by "Xavier Hanin (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IVY-480?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Xavier Hanin resolved IVY-480.
------------------------------

       Resolution: Fixed
    Fix Version/s: 2.0

I've applied your patch (with a minor fix on arraycopy), it will now be possible to proceed as you suggested. I don't think that deprecating -args is really necessary though, so there won't be a deprecation message when used.

> Allow "main" parameters to be passed directly (instead of using -args flag)
> ---------------------------------------------------------------------------
>
>                 Key: IVY-480
>                 URL: https://issues.apache.org/jira/browse/IVY-480
>             Project: Ivy
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 1.4.1
>            Reporter: Archie Cobbs
>             Fix For: 2.0
>
>         Attachments: argspatch.txt
>
>
> When running ivy in standalone mode using the {{-main}} flag, any extra parameters passed on the command line (i.e., not as flag arguments) are simply ignored.
> E.g., if I invoke {{java fr.jayasoft.ivy.Main -main com.exmaple.Main foo bar}} the {{foo bar}} parameters are ignored. To pass "foo" and "bar" to my main method, I have to use {{-args foo}} and {{-args bar}}.
> Suggestion: when using the {{-main}} flag, allow the parameters to the main method to be passed directly on the command line as "extra" parameters, as an alternative to using the {{-args}} flag.
> The motivation for this is that this would be much easier to deal with in shell scripts. E.g. suppose I want to write a shell script {{/usr/bin/foo}} which uses ivy to resolve dependencies and execute some main class {{com.example.foo.Main}}. To do this I'd have to parse the command line into individual arguments, then precatenate each one with a {{-args}} flag, etc. This sounds hard enough, but when you consider that some parameters may be quoted, it becomes nearly impossible. With the change suggested here, it would become trivial: I'd just do something like {{ivy -ivy /usr/share/foo.ivy -main com.example.foo.Main ${1+"$@"} }} in the shell script.
> If this is implemented, it should probably become the recommended approach, and {{-args}} be deprecated.
> As a side note, the {{-args}} flag is mis-named: it should be called {{-arg}} instead (but I'd prefer to have it just be deprecated).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.