Skip to content

Conversation

@glennblock
Copy link
Contributor

This fixes #1085

Update: -e was chosen to align with the existing *nix precedent. Mono's REPL uses this and node as well. Thanks to @migueldeicaza for the suggestion!

It adds a new switch for immediately executing loose code. Also adds a new convenience overload to the ScriptCsExe.Run() method.

example:

scriptcs -e 'Console.WriteLine("""Hello from scriptcs""");'

Note: Depending on the shell you use you may have to jump through different hoops for passing spaces / quoted strings. The example is using Powershell. To do this from the cmd prompt you would use:

scriptcs -e 'Console.WriteLine(\"\"\"Hello from scriptcs\"\"\");'

@glennblock glennblock force-pushed the 1085 branch 2 times, most recently from 4a42570 to 14abb8f Compare December 28, 2015 02:37
@glennblock glennblock changed the title Adds new -x and -exec options which will immediately execute a script Adds new -e and -exec options which will immediately execute a script Dec 28, 2015
@glennblock glennblock changed the title Adds new -e and -exec options which will immediately execute a script Adds new -e and --eval options which will immediately execute a script Feb 14, 2016

namespace ScriptCs.Command
{
internal class ExecuteLooseScriptCommand : IExecuteLooseScriptCommand
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is almost a copy of ExecuteScriptCommand, the only difference appears to be _scriptExecutor.Execute vs _scriptExecutor.ExecuteScript.
It would be better to add a common abstract class and share most of the logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok sounds good.

@filipw
Copy link
Member

filipw commented Feb 28, 2016

@glennblock this is great, very welcome option. What I do in a scriptcs extension for VS Code, to allow script snippet evaluation is I saved it to a temp file (lol https://github.com/filipw/vscode-scriptcs-runner/blob/master/src/extension.ts#L81) and invoke that haha so it's very welcome

Just left a comment to avoid code copying/duplication

@glennblock
Copy link
Contributor Author

Great suggestion. Glad you find it useful.

@filipw
Copy link
Member

filipw commented Feb 29, 2016

Also, according to TC this PR has 28 failing tests, so can you please double check everything passes OK

@adamralph
Copy link
Contributor

@filipw it's because of this #1127

@glennblock
Copy link
Contributor Author

Yeah it is very inconsistent that this path error pops up
On Sun, Feb 28, 2016 at 4:20 PM Adam Ralph notifications@github.com wrote:

@filipw https://github.com/filipw it's because of this #1127
#1127


Reply to this email directly or view it on GitHub
#1129 (comment).

@adamralph
Copy link
Contributor

It probably depends which build agent it runs on.

@adamralph
Copy link
Contributor

Scratch that. The test failures are genuine. I can reproduce them locally.

They were introduced with the merge of #1134

If I build the commit on the dev branch immediately before that merge, everything is fine.

@filipw
Copy link
Member

filipw commented Feb 29, 2016

how is that possible, given that the build status reported on that PR was green

@glennblock
Copy link
Contributor Author

@adamralph looking into this now

@adamralph
Copy link
Contributor

image

Only the Travis build was allowed to run before merging, TC was still to kick in. Why the tests are passing in Linux and not in Windows, I'm not sure.

@glennblock
Copy link
Contributor Author

@adamralph I see the errors. I'm going to fix in the original branch and send another PR.

@glennblock
Copy link
Contributor Author

Working on this, I think I see the issue.

On Sun, Feb 28, 2016 at 6:09 PM Adam Ralph notifications@github.com wrote:

[image: image]
https://cloud.githubusercontent.com/assets/677704/13383990/1532a020-de91-11e5-9755-cf75c68cd708.png

Only the Travis build was allowed to run before merging, TC was still to
kick in. Why the tests are passing in Linux and not in Windows, I'm not
sure.


Reply to this email directly or view it on GitHub
#1129 (comment).

@glennblock
Copy link
Contributor Author

Fixed. I'll send a new PR shortly.

On Sun, Feb 28, 2016 at 6:54 PM Glenn Block glenn.block@gmail.com wrote:

Working on this, I think I see the issue.

On Sun, Feb 28, 2016 at 6:09 PM Adam Ralph notifications@github.com
wrote:

[image: image]
https://cloud.githubusercontent.com/assets/677704/13383990/1532a020-de91-11e5-9755-cf75c68cd708.png

Only the Travis build was allowed to run before merging, TC was still to
kick in. Why the tests are passing in Linux and not in Windows, I'm not
sure.


Reply to this email directly or view it on GitHub
#1129 (comment).

@glennblock
Copy link
Contributor Author

@adamralph @filipw all tests passing now based on my last DOH fix.

@glennblock
Copy link
Contributor Author

@adamralph any idea why TC seems to be slow in picking up the changes?

@glennblock
Copy link
Contributor Author

@filipw ready to merge!

@adamralph
Copy link
Contributor

@adamralph any idea why TC seems to be slow in picking up the changes?

@glennblock Codebetter CI is just slow 😒

@glennblock
Copy link
Contributor Author

@scriptcs/core this is waiting on someone to click merge ;-)

@glennblock
Copy link
Contributor Author

@adamralph Travis is lying

@adamralph
Copy link
Contributor

@glennblock I kicked off the build again and it passed.


var assemblyPaths = Enumerable.Empty<string>();
var workingDirectory = _fileSystem.CurrentDirectory;
assemblyPaths = _assemblyResolver.GetAssemblyPaths(workingDirectory);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The declaration and assignment of assemblyPaths can be combined on this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are being a little anal here

directory = ScenarioDirectory.Create(scenario);
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
script = @"Console.WriteLine(""""""Hello World!"""""");";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does Windows need 3 double quotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it does. This has been thoroughly tested and it is apparently by design.

@adamralph
Copy link
Contributor

@glennblock I left a couple of comments regarding the implementation.

Regarding behaviour, I'd like to investigate the result of combinations of a filename, an eval script and the REPL switch:

File Script -R Result
REPL
X file, exit
X script, exit
X X script, exit1
X REPL
X X file, REPL
X X script, exit2
X X X script, exit3
  1. We are saying that a script trumps a file. That's fine, but out of interest, how easy would it be to run both in the same session? If possible I guess we'd have to say which comes first, file or script?
  2. I think this is problematic. If I pass a file and -R, the file is executed and then I get REPL. I think it's astonishing that when pass a script and -R that I don't get a REPL.
  3. This is a combination of points 1 and 2.

@glennblock
Copy link
Contributor Author

I see your point, but these seem like small issues to me. The manor use case here is to allow immediately executing a command that is passed at the command line. The other combinations are nice to have, sure they bring more consistency, but still nice to have and unlikely to be used.

Using -r however is there to allow pre-loading a bunch of stuff when you come into the REPL so it executes and then you can use the loaded objects. This feels far less valuable in this context.

@glennblock glennblock merged commit e31b194 into scriptcs:dev Dec 29, 2016
@glennblock glennblock deleted the 1085 branch January 3, 2017 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow passing code to scriptcs at the command line

3 participants