The Wayback Machine - https://web.archive.org/web/20240713003448/https://github.com/dotnet/roslyn/pull/5857
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

csi improvements #5857

Merged
merged 4 commits into from
Oct 13, 2015
Merged

csi improvements #5857

merged 4 commits into from
Oct 13, 2015

Conversation

tmat
Copy link
Member

@tmat tmat commented Oct 10, 2015

Improves and cleans up handling of command line arguments for csi.

Adds some alternative forms for arguments:

csc:

Existing arg New arg Decription
/lib /libpath, /libpaths adds directory(ies) to metadata search paths

vbc:

Existing arg New arg Decription
/libpath /lib /libpaths adds directory(ies) to metadata search paths

csi:

Existing arg New arg Description
/lib, /libpath, /libpaths adds directory(ies) to metadata search paths
/loadpath, /loadpaths adds directory(ies) to source search paths
/u, /using /usings, /import, /imports adds import(s) to global imports

Also changes "--" to match ruby/python/*nix. It indicates that the remaining arguments should not be treated as options.

csi only accepts a single script on the command line, any arguments following the script file name is now considered an argument to the script, not to csi.

Command line Script args:
csi -- script.csx b c ["b", "c"], runs script file "script.csx"
csi -- @script.csx a b c ["a", "b", "c"], runs script file "@script.csx"
csi -- -script.csx a b c ["a", "b", "c"], runs script file "-script.csx"
csi script.csx -- a b c ["--", "a", "b", "c"]
csi script.csx a b c ["a", "b", "c"]
csi script.csx a -- b c ["a", "--", "b", "c"]

"/i" or "-i" is now used to launch REPL after executing specified script with arguments:

csi -i script.csx a b c
output of script.csx
> Args
List<string>(3) { "a", "b", "c" }

The design mimics Python.

Fixes #5277

@tmat
Copy link
Member Author

tmat commented Oct 12, 2015

@dotnet/roslyn-compiler @amcasey @KevinH-MS @cston

@gafter
Copy link
Member

gafter commented Oct 12, 2015

Do you mean the rest of the arguments after -- are treated as file names?

@tmat
Copy link
Member Author

tmat commented Oct 12, 2015

@gafter Yes, or script arguments. See https://en.wikipedia.org/wiki/Command-line_interface#Option_conventions_in_Unix-like_systems

@amcasey
Copy link
Member

amcasey commented Oct 12, 2015

Does each row of that table have a corresponding unit test?

@agocke
Copy link
Member

agocke commented Oct 12, 2015

馃憤 The -- change is great.

@agocke
Copy link
Member

agocke commented Oct 12, 2015

@tmat Actually, some of these results are confusing. Let's chat about the goals here.

@ManishJayaswal
Copy link
Contributor

What does the very first case do? If everything following "--" is an argument, what gets run?
Are you just listing unit tests here?

@agocke
Copy link
Member

agocke commented Oct 12, 2015

@TyOverby Wrote up a proposed usage in the gist here: https://gist.github.com/TyOverby/41ac9e16e44f2db6376c

I agree with his proposed behavior, although I don't think special syntax should be specified for -i or -- -- those should just be additional csi args IMO.

@TyOverby
Copy link
Contributor

As a linux user, I would expect the following syntax out of an interpreter CLI.

Usage

    csi [ csi-arguments ] [ -i ]
    csi [ csi-arguments ]  [ script | - ] [ script-arguments ]
    csi [ csi-arguments ] -i [ script-arguments ]
    csi [ csi-arguments ] -- [ script | - ] [ script-arguments ]
    csi [ csi-arguments ] -i -- [ script-arguments ]

Script Arguments

In all of these executions, I either expect to have my script name to be passed in on the arguments or not. This is how other scripting languages solve this problem

  • Python: Always pass in script name, then script-arguments (script-name is the empty string if used in interactive mode)
  • Ruby: Never pass in script name
  • Node: Always pass in executable name (/usr/bin/node), script name if it exists (bad!)

I'm ok with any of these decisions as long as it's consistent. That said, I think Ruby's option is the better choice and I'll use that in further examples.

The meaning of "--"

"--" should only mean "we are done parsing csi-arguments." If we have already started parsing csi-arguments, then include the "--" in the script-arguments, otherwise leave it out.

csi -- -test.csx a b c    =>   run -test.csx with ["a",  "b", "c"]
csi test.csx -- a b c     =>   run test.csx with  ["--", "a", "b", "c"]

For example, there should be no difference between

csi -- script.csx a b c

and

csi script.csx a b c

The meaning of "-i"

When "-i" is passed, csi will be started in "interactive mode" and a file name will not be looked for. If the file name is specified it will be executed before starting interactive loop.

The only other way to enter "interactive mode" would be to pass in no script-arguments.

csi          # Open in interactive mode
csi -i       # Open in interactive mode
csi a b c    # Try to execute the script "a"
csi -i a b c # executes script "a" with argumetns ["b", "c"] and drops to interactive afterwards

csi -i a b c # Open interactive mode with arguments "a", "b", and "c"

These semantics are the same as python's

The meaning of "-"

When a single dash "-" is used in the place of a filename, instead of reading a file, stdin is used instead.

@TyOverby
Copy link
Contributor

I agree with his proposed behavior, although I don't think special syntax should be specified for -i or -- -- those should just be additional csi args IMO.

Totally agree on -i, but because -- has special semantic meaning when it comes to parsing the rest of the arguments, I left it in the usage section in order to draw attention to those semantics.

@tmat
Copy link
Member Author

tmat commented Oct 12, 2015

Yeah, changing - to -i. We can implement - later.

@TyOverby
Copy link
Contributor

Specifically, in the table, here are what I would expect:

Command line Script args(old) Script args (proposed)
csi -- script.csx b c ["script.csx", "b", "c"] ["b", "c"], runs "script.csx"
csi -- @script.csx a b c ["a", "b", "c"], runs script file "@script.csx" [same as old]
csi -- -script.csx a b c ["a", "b", "c"], runs script file "-script.csx" [same as old]
csi script.csx -- a b c ["--", "a", "b", "c"] [same as old]
csi script.csx a b c ["a", "b", "c"] [same as old]
csi script.csx a -- b c ["a", "--", "b", "c"] [same as old]
csi -i script.csx a b c ["script.csx", "a", "b", "c"] in interactive runs "script.csx" and then drops to interactive with arguments ["a", "b", "c"]
csi -i -- script.csx a b c ["script.csx", "a", "b", "c"] in interactive runs "script.csx" and then drops to interactive with arguments ["a", "b", "c"]

@tmat
Copy link
Member Author

tmat commented Oct 13, 2015

@TyOverby I have modified the impl to match Python, except for not implementing support for "-" (we can add it later).

The behavior is slightly different from what you suggest in the table above. I have updated the table above.

@TyOverby
Copy link
Contributor

@tmat: How are you judging if the first argument to csi is a script file or not?

What is it that makes these different?

csi -i a b c
csi -i script.csx a b c

@tmat
Copy link
Member Author

tmat commented Oct 13, 2015

@TyOverby It always is.

In Python "-" means read the input from tty. That essentially means there is no script file to execute, just the stdin.

@TyOverby
Copy link
Contributor

@tmat So what is the way to pass in arguments to an interpreted mode that doesn't run a script by default?

@tmat
Copy link
Member Author

tmat commented Oct 13, 2015

Not for U1. Will add later. The scenario is imo not important.

@TyOverby
Copy link
Contributor

Ok great! LGTM

@ManishJayaswal
Copy link
Contributor

@JohnHamby FYI - this would resolve #5288

@ManishJayaswal
Copy link
Contributor

@tmat what would be the syntax to pass arguments to csi interactive mode without a script file when we add it later?

@tmat
Copy link
Member Author

tmat commented Oct 13, 2015

@ManishJayaswal
Syntax: "-" would be used instead of the file name, e.g. "csi - a b c"

API review - yes, it's separate.

@ManishJayaswal
Copy link
Contributor

@tmat Ok. So the example at the very top in description is incorrect then?

csi -i a b c

Args
List(3) { "a", "b", "c" }

@tmat
Copy link
Member Author

tmat commented Oct 13, 2015

Right. Fixed.

@ManishJayaswal
Copy link
Contributor

馃憤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants