Giter VIP home page Giter VIP logo

Comments (10)

laurent22 avatar laurent22 commented on May 25, 2024

@dufferzafar, just to be sure, did you solve your issue? I didn't try but I guess it can be sorted out by quoting the executable path. Did you try this?

It's true that the current way it's working could be improved. Perhaps massren could detect the ".exe" part in Windows and, if found, quote the path automatically.

from massren.

dufferzafar avatar dufferzafar commented on May 25, 2024

I did solve the issue, by moving my Sublime text to: F:\Sublime\subl.exe

LIKE A BOSS 😄

from massren.

hashhar avatar hashhar commented on May 25, 2024

Still not fixed.
What do we do to handle flags. Mostly flags start with either dashes or slahes and will have a space preceding them.
C:\Program Files\VSCode.exe -g -x or C:\Program Files\VSCode.exe /g /x should be handled.

Can we split only when we find both a space and a - or / or --?

from massren.

hashhar avatar hashhar commented on May 25, 2024

This works but removes the leading -, --, and /.

pieces := make([]string,0)
if (strings.Contains(editorCmd, "--")) {
    pieces = strings.Split(editorCmd, " --")
} else if (strings.Contains(editorCmd, " -")) {
    pieces = strings.Split(editorCmd, " -")
} else if (strings.Split(editorCmd, " /") {
    pieces = strings.Split(editorCmd, " /")
} else {
    pieces = strings.Split(editorCmd, " ")
} 
pieces = append(pieces, "file1.txt")

This turns C:/Program Files/VSCode.exe -f -g and a file.txt to C:/Program Files/VSCode.exe f g file.txt.
Also it seems we cannot mix and match two kinds of flags at once (like vscode.exe --newwindow -f)

from massren.

laurent22 avatar laurent22 commented on May 25, 2024

Hmm, yes that seems quite complex because it indeed looks like we should parse the flags if we want to support this properly.

Ideally, I think the test cases we should be able to handle are:

subl
/usr/bin/vim -f
"F:\Sublime Text 3\sublime_text.exe" -n -w
subl -w --command "something with spaces"
notepad /PT

Case that we do not need to handle:

F:\Sublime Text 3\sublime_text.exe -n -w

Because this is not a valid command since there should be quotes around the executable path and name.

Maybe a simple solution would to use a dedicated flag parser like go-flags?

from massren.

hashhar avatar hashhar commented on May 25, 2024

Go-flag looks well suited, we can even parse from strings.

from massren.

hashhar avatar hashhar commented on May 25, 2024

I'll add those testcases to a separate test file for now so that they don't hinder with the Travis CI builds.

from massren.

hashhar avatar hashhar commented on May 25, 2024

I got this going now. The code is working locally on the testcases. I dont have internet right now (on my mobile currently). I'll get it through Travis and submit a PR once i get hold of internet.

from massren.

laurent22 avatar laurent22 commented on May 25, 2024

Thanks, I've moved the parsing code to a function so that we can unit test it, and added the unit tests for it in Test_parseEditorCommand. At the moment, some of the tests are failing due to quote and space issues. Basically, the tests check that the function returns the executable path and the arguments. For example, they expect this:

"/usr/bin/vim -v -i"

is going to be parsed into:

executable: /usr/bin/vim
args (a slice): [ -v, -i ]

and:

subl -w --command "something with spaces"

into:

executable: subl
args: [ -w, --command, something with spaces ]

Maybe I didn't refactor your code correctly though, please have a look just to make sure. The command to run the tests is go test.

from massren.

hashhar avatar hashhar commented on May 25, 2024

I'll check it out by Saturday. Thanks for the refactoring.

Although I think we both have different ideas of how we would like to implement it.
The way I had written the code will never allow the second case you mentioned to pass. It always expects quotes when there are spaces.
But i think what you are aiming for is better. I'll try and implement that too.

from massren.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.