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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand ide:// protocol to do more than just clone #44

Open
maxandersen opened this issue Aug 26, 2020 · 17 comments
Open

expand ide:// protocol to do more than just clone #44

maxandersen opened this issue Aug 26, 2020 · 17 comments
Milestone

Comments

@maxandersen
Copy link
Member

right now we just have ide://<url to clone>, but would be interesting to have stuff like ide://clone?repo=<url> and ide://open?path=<url-to-file> where open would clone if needed and open the file - if repo already cloned just open the file.

Similar could add things like ide://open?path=<url-to-file>&line=27 to open file and go to line 27.

@maxandersen
Copy link
Member Author

maxandersen commented Aug 26, 2020

related #41 and #7

@maxandersen
Copy link
Member Author

maxandersen commented Jun 24, 2021

idea:

ide://clone?repo=[url]&path=src/main/java/test.java

clone if necessary, open file path

ide://clone?open=https://github.com/starfixdev/starfix/blob/master/cli/installer/windows/installer/starfix.reg

and have "magic parsing" that detects this is a github backed url and do the right clooning and open.
similar can be done for bitbucket, gitlab, etc..

@maxandersen
Copy link
Member Author

@maxandersen
Copy link
Member Author

first step: clone/reuse repo and open file path

second step: handle case where branch does not match or file might not exist locally

@maxandersen maxandersen added this to the M2 2021 milestone Jun 24, 2021
@fahad-israr
Copy link
Collaborator

I tried working with VS Code.
Vs Code provides code command to work from Terminal.

C:\Users\Fahad Israr>code --help
Visual Studio Code 1.57.1

Usage: code.exe [options][paths...]

To read output from another program, append '-' (e.g. 'echo Hello World | code.exe -')

Options
  -d --diff <file> <file>           Compare two files with each other.
  -a --add <folder>                 Add folder(s) to the last active window.
  -g --goto <file:line[:character]> Open a file at the path on the specified
                                    line and character position.
  -n --new-window                   Force to open a new window.
  -r --reuse-window                 Force to open a file or folder in an
                                    already opened window.
  -w --wait                         Wait for the files to be closed before
                                    returning.
  --locale <locale>                 The locale to use (e.g. en-US or zh-TW).
  --user-data-dir <dir>             Specifies the directory that user data is
                                    kept in. Can be used to open multiple
                                    distinct instances of Code.
  -h --help                         Print usage.
  • Using the -g argument we can open the file on a specific line and character but the issue is its opening individually.
  • We can use --n or -r to decide to open a new window or reuse the existing one but either way the file opens up individually without the rest of the project.
  • If we intend to open the file only then this works fine otherwise will have to think of some other solution.

@maxandersen
Copy link
Member Author

code ~/code/myrepo ~/code/myrepo/src/myfile.java

Works as far as I'm aware.

@fahad-israr
Copy link
Collaborator

Oh wow.. that worked !!
I wasn't aware of that and was just trying things from the vscode cli help .

@fahad-israr
Copy link
Collaborator

  • Whenever we write something like this ide://clone?open=https://github.com/starfixdev/starfix/blob/master/cli/installer/windows/installer/starfix.reg starfix application will tell us it as an invalid argument.
  • To make this work we can write starfix clone https://github.com/starfixdev/starfix/blob/master/cli/installer/windows/installer/starfix.reg .
  • To achieve this we'd have to pre-process this into something like starfix clone https://git..... .Parsing in Java is easy but I ain't sure how'd I validate it with Picocli . I am currently exploring Picocli docs to see if I can find something helpful there.

@maxandersen
Copy link
Member Author

Is this not just because the command does not have first argument defined ?

i.e. add the following:

@CommandLine.Parameters()
    URI uri;

    @Override
    public void run() {
        System.out.println(uri);
    }

and it will let you pass the URI in as first free argument.

@fahad-israr
Copy link
Collaborator

We have the first argument defined right ?
Aren't clone and config the first arguments ?

@maxandersen
Copy link
Member Author

Yes but you can other option which will work when it is not clone or config.

@fahad-israr
Copy link
Collaborator

fahad-israr commented Jul 4, 2021

  • This will lead us to have something like this :
@Command(name = "clone"){
// Into Clone Command
}

@Command(name = "config) {
// Into Config Command
}
@CommandLine.Parameters()
    URI uri;

    @Override
    public void run() {
        System.out.println(uri);
    }
  • With this structure picocli will always expect a parameter.
  • For instance, lets execute : starfix clone https://git/user/repo . This is what we get:
Missing required parameter: '<uri>'
Usage: <main class> [-hV] <uri> [COMMAND]
      <uri>
  -h, --help      Show this help message and exit.
  -V, --version   Print version information and exit.
Commands:
  clone
  config

@fahad-israr
Copy link
Collaborator

I was wondering if Picocli provides something like we have for switch case in Java.

switch(var)
case "clone": 
case "config":
default:
{
// ide handler can fit in here
}

@maxandersen
Copy link
Member Author

Mark the Uri parameter as optional. Then it is not required. See picocli Docs for the syntax.

@fahad-israr
Copy link
Collaborator

fahad-israr commented Jul 5, 2021

  • Yes yes,that's what I was searching for but read through somewhere in the Picocli that single valued parameters are mandatory
  • Recently learnt about setting arity , probably setting it can make it optional. I am trying with that .

@fahad-israr
Copy link
Collaborator

I had made changes to the PR yesterday.
Have a look if it looks fine.

@fahad-israr
Copy link
Collaborator

Can close this issue ?

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

No branches or pull requests

2 participants