Melkeydev / go-blueprint

Go-blueprint allows users to spin up a quick Go project using a popular framework
https://docs.go-blueprint.dev/
MIT License
5.81k stars 333 forks source link

[Feature Request] Add option to include slashes and dots in project name #285

Closed wojcraft closed 2 months ago

wojcraft commented 4 months ago

Tell us about your feature request

It's not possible to enter project name as this: github.com/wojcraft/project-name - I've got used to this naming for learning and I see it also affects imports. Can you help me with that?

Here is screenshot of a input that needs to be modified in order to solve this request image

Disclaimer

Ujstor commented 4 months ago

You are right, it is not possible to use '/' as input in the project name. If the go-blueprint create -n github.com/user/project-name command is executed, the CLI would create subdirectories after '/'. Thanks for addressing this....it needs to be fixed.

Ujstor commented 4 months ago

This is an easy fix, the only thing that needs to be changed is the regex in the sanitizeInput() function (textinput.go):

func sanitizeInput(input string) error {
    matched, err := regexp.Match("^[a-zA-Z0-9_\\-\\./]+$", []byte(input))
    if !matched {
        return fmt.Errorf("string violates the input regex pattern, err: %v", err)
    }
    return nil
}
wojcraft commented 4 months ago

This is an easy fix, the only thing that needs to be changed is the regex in the sanitizeInput() function (textinput.go):

func sanitizeInput(input string) error {
  matched, err := regexp.Match("^[a-zA-Z0-9_\\-\\./]+$", []byte(input))
  if !matched {
      return fmt.Errorf("string violates the input regex pattern, err: %v", err)
  }
  return nil
}

/^[a-zA-Z0-9_\-\.\/]+$

I rather meant to make dots and slashes available at the same time. To allow urls like github.com/wojcraft/test

I embedded screenshot

Screenshot_2024-07-27-21-56-41-73_40deb401b9ffe8e1df2f1cc5ba480b12.jpg

Ujstor commented 4 months ago

I agree...I did just a quick test.

H0llyW00dzZ commented 3 months ago

Wait, I think you don't have to explicitly use a regex because it's a string.

wojcraft commented 3 months ago

Dear @Ujstor,

So, are you going to implement this feature? I feel a little disoriented looking at this issue, so I'm just asking about a status of it.

If you want to know more details about what I mean in this quite small Feature Request, just let me know!

All the best! Wojcraft

Ujstor commented 3 months ago

The issue is open, and anyone can solve it and submit a PR :)

Patel-Raj commented 3 months ago

Hi @Ujstor

If the project name entered is "github.com/wojcraft/project-name", could you please suggest what should be the expected behavior from 1 or 2?

Behavior 1: root folder name: project-name module name: github.com/wojcraft/project-name

Behavior 2: root folder name: github.com/wojcraft/project-name module name: github.com/wojcraft/project-name

If behavior 2 is expected, than is it possible on Linux based operating systems to have / in directory name?

Ujstor commented 3 months ago

@Patel-Raj I think option number 1 would be best to implement because of cross-platform compatibility: root folder name: project-name module name: github.com/wojcraft/project-name

Behavior 2 is what you get if we change the sanitizeInput function and allow . and /. In this case, the blueprint’s default behavior will create a directory tree github.com/wojcraft/project-name. As you pointed out, on Windows, this will be a big issue.

@H0llyW00dzZ This is why regex is used, not just a plain string.

H0llyW00dzZ commented 3 months ago

@Patel-Raj I think option number 1 would be best to implement because of cross-platform compatibility: root folder name: project-name module name: github.com/wojcraft/project-name

Behavior 2 is what you get if we change the sanitizeInput function and allow . and /. In this case, the blueprint’s default behavior will create a directory tree github.com/wojcraft/project-name. As you pointed out, on Windows, this will be a big issue.

@H0llyW00dzZ This is why regex is used, not just a plain string.

It can be more easily achieved using the URL builder from the standard library and removing the scheme (http/https) instead of using regex.

for example:

func sanitizeInput(input string) error {
    // Remove the URL scheme (e.g., http://, https://) from the input
    input = strings.TrimPrefix(strings.TrimPrefix(input, "https://"), "http://")

    _, err := url.Parse("//" + input)
    if err != nil {
        return fmt.Errorf("invalid input: %v", err)
    }
    return nil
}
H0llyW00dzZ commented 3 months ago

And then For non-URL cases, it can be achieved by using regex because if using regex for URIs/URLs such as github.com/wojcraft/project-name, it would be more complex to create a regex pattern (e.g., we would have to find the pattern again) when trying to use other URLs, for example, example.com/project-name, etc.