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

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

Closed
1 task done
wojcraft opened this issue Jul 25, 2024 · 11 comments · Fixed by #298
Closed
1 task done

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

wojcraft opened this issue Jul 25, 2024 · 11 comments · Fixed by #298
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@wojcraft
Copy link

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

  • I agree
@wojcraft wojcraft added the enhancement New feature or request label Jul 25, 2024
@Ujstor
Copy link
Collaborator

Ujstor commented Jul 25, 2024

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
Copy link
Collaborator

Ujstor commented Jul 27, 2024

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
Copy link
Author

wojcraft commented Jul 27, 2024

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
Copy link
Collaborator

Ujstor commented Jul 27, 2024

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

@Ujstor Ujstor added the good first issue Good for newcomers label Aug 15, 2024
@H0llyW00dzZ
Copy link
Contributor

H0llyW00dzZ commented Aug 15, 2024

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

@wojcraft
Copy link
Author

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
Copy link
Collaborator

Ujstor commented Aug 22, 2024

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

@Patel-Raj
Copy link
Contributor

Patel-Raj commented Aug 24, 2024

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
Copy link
Collaborator

Ujstor commented Aug 25, 2024

@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
Copy link
Contributor

@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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants