11package main
22
33import (
4- "fmt"
5- "io"
6- "net/http"
7- "os"
8- "strings"
9- "time"
4+ "fmt"
5+ "io"
6+ "net/http"
7+ "os"
8+ "strings"
9+ "time"
1010)
1111
1212const defaultBaseURL = "https://start.spring.io"
@@ -15,35 +15,36 @@ const defaultBaseURL = "https://start.spring.io"
1515var version = "dev"
1616
1717type options struct {
18- baseURL string
19- target string // zip or tgz (only zip implemented for now)
20- projectType string // maven-project, gradle-project, gradle-build
21- language string // java, kotlin, groovy
22- bootVersion string
23- groupID string
24- artifactID string
25- name string
26- description string
27- packageName string
28- packaging string // jar or war
29- javaVersion string // 8, 11, 17, 21, etc.
30- dependencies string // comma-separated
31- baseDir string
18+ baseURL string
19+ target string // zip or tgz (only zip implemented for now)
20+ projectType string // maven-project, gradle-project, gradle-build
21+ language string // java, kotlin, groovy
22+ bootVersion string
23+ groupID string
24+ artifactID string
25+ name string
26+ description string
27+ packageName string
28+ packaging string // jar or war
29+ javaVersion string // 8, 11, 17, 21, etc.
30+ configFileFormat string // properties or yaml
31+ dependencies string // comma-separated
32+ baseDir string
3233
3334 output string // output file path for zip
3435 extract bool // extract zip to directory (baseDir)
3536 dryRun bool // print URL and exit
3637 timeout int // seconds
3738 verbose bool
3839
39- // interactive control (not a flag)
40- interactive bool
40+ // interactive control (not a flag)
41+ interactive bool
4142
42- // show version and exit
43- showVersion bool
43+ // show version and exit
44+ showVersion bool
4445
45- // show license and notices and exit
46- showLicense bool
46+ // show license and notices and exit
47+ showLicense bool
4748}
4849
4950func main () {
@@ -54,95 +55,95 @@ func main() {
5455 }
5556}
5657
57- /* parseFlags moved to parser.go
58- var o options
59-
60- flag.StringVar(&o.baseURL, "base-url", defaultBaseURL, "Spring Initializr base URL")
61- flag.StringVar(&o.target, "target", "zip", "Archive format: zip (default)")
62- flag.StringVar(&o.projectType, "type", "maven-project", "Project type: maven-project, gradle-project, or gradle-build")
63- flag.StringVar(&o.language, "language", "java", "Language: java, kotlin, or groovy")
64- flag.StringVar(&o.bootVersion, "boot-version", "", "Spring Boot version (optional)")
65- flag.StringVar(&o.groupID, "group-id", "com.example", "Group ID")
66- flag.StringVar(&o.artifactID, "artifact-id", "demo", "Artifact ID")
67- flag.StringVar(&o.name, "name", "demo", "Project name")
68- flag.StringVar(&o.description, "description", "Demo project for Spring Boot", "Project description")
69- flag.StringVar(&o.packageName, "package-name", "", "Base package name (default: groupId + '.' + artifactId)")
70- flag.StringVar(&o.packaging, "packaging", "jar", "Packaging: jar or war")
71- flag.StringVar(&o.javaVersion, "java-version", "21", "Java version, e.g. 17 or 21")
72- flag.StringVar(&o.dependencies, "dependencies", "", "Comma-separated dependency IDs, e.g. web,data-jpa,postgresql")
73- flag.StringVar(&o.baseDir, "base-dir", "", "Project root directory name (default: artifactId)")
74-
75- flag.StringVar(&o.output, "output", "", "Output zip file path (default: <artifactId>.zip)")
76- flag.BoolVar(&o.extract, "extract", false, "Extract archive into directory (uses base-dir)")
77- flag.BoolVar(&o.dryRun, "dry-run", false, "Print the generated URL and exit")
78- flag.IntVar(&o.timeout, "timeout", 60, "Download timeout in seconds")
79- flag.BoolVar(&o.verbose, "v", false, "Verbose output")
80- flag.BoolVar(&o.interactive, "interactive", false, "Interactive TUI mode")
81- flag.BoolVar(&o.interactive, "i", false, "Interactive TUI mode (shorthand)")
82- flag.BoolVar(&o.showVersion, "version", false, "Print version and exit")
83- flag.BoolVar(&o.showVersion, "V", false, "Print version and exit (shorthand)")
84- flag.BoolVar(&o.showLicense, "license", false, "Print licenses (app + NOTICE) and exit")
85- flag.BoolVar(&o.showLicense, "L", false, "Print licenses (app + NOTICE) and exit (shorthand)")
86-
87- flag.Usage = func() {
88- fmt.Fprintf(os.Stderr, "Spring Initializr CLI (Go)\n\n")
89- fmt.Fprintf(os.Stderr, "Usage: %s [options]\n\n", filepath.Base(os.Args[0]))
90- fmt.Fprintf(os.Stderr, "Examples:\n")
91- fmt.Fprintf(os.Stderr, " %s --type maven-project --language java \\\n", filepath.Base(os.Args[0]))
92- fmt.Fprintf(os.Stderr, " --group-id com.example --artifact-id demo \\\n")
93- fmt.Fprintf(os.Stderr, " --dependencies web,data-jpa --extract\n\n")
94- flag.PrintDefaults()
95- fmt.Fprintf(os.Stderr, "\nNotes:\n- Dependencies are Spring Initializr IDs (e.g. web, data-jpa, security).\n")
96- fmt.Fprintf(os.Stderr, "- If --extract is set, the zip will be downloaded and extracted into --base-dir (defaults to artifact-id).\n")
97- fmt.Fprintf(os.Stderr, "- Use --dry-run to just print the URL.\n")
98- fmt.Fprintf(os.Stderr, "- Use --version or -V to print the version.\n")
99- fmt.Fprintf(os.Stderr, "- Use --license or -L to print licenses and exit.\n")
100- }
101-
102- flag.Parse()
103-
104- // Fill derived defaults
105- if o.baseDir == "" {
106- o.baseDir = o.artifactID
107- }
108- if o.packageName == "" {
109- o.packageName = sanitizePackage(o.groupID + "." + o.artifactID)
110- } else {
111- o.packageName = sanitizePackage(o.packageName)
112- }
113- if o.output == "" {
114- o.output = o.artifactID + ".zip"
115- }
116-
117- // Normalize some shortcuts
118- switch strings.ToLower(o.projectType) {
119- case "maven", "maven-project":
120- o.projectType = "maven-project"
121- case "gradle", "gradle-project":
122- o.projectType = "gradle-project"
123- case "gradle-build":
124- // as-is
125- default:
126- // keep as provided, server will validate
127- }
58+ /*
59+ parseFlags moved to parser.go
60+ var o options
61+
62+ flag.StringVar(&o.baseURL, "base-url", defaultBaseURL, "Spring Initializr base URL")
63+ flag.StringVar(&o.target, "target", "zip", "Archive format: zip (default)")
64+ flag.StringVar(&o.projectType, "type", "maven-project", "Project type: maven-project, gradle-project, or gradle-build")
65+ flag.StringVar(&o.language, "language", "java", "Language: java, kotlin, or groovy")
66+ flag.StringVar(&o.bootVersion, "boot-version", "", "Spring Boot version (optional)")
67+ flag.StringVar(&o.groupID, "group-id", "com.example", "Group ID")
68+ flag.StringVar(&o.artifactID, "artifact-id", "demo", "Artifact ID")
69+ flag.StringVar(&o.name, "name", "demo", "Project name")
70+ flag.StringVar(&o.description, "description", "Demo project for Spring Boot", "Project description")
71+ flag.StringVar(&o.packageName, "package-name", "", "Base package name (default: groupId + '.' + artifactId)")
72+ flag.StringVar(&o.packaging, "packaging", "jar", "Packaging: jar or war")
73+ flag.StringVar(&o.javaVersion, "java-version", "21", "Java version, e.g. 17 or 21")
74+ flag.StringVar(&o.dependencies, "dependencies", "", "Comma-separated dependency IDs, e.g. web,data-jpa,postgresql")
75+ flag.StringVar(&o.baseDir, "base-dir", "", "Project root directory name (default: artifactId)")
76+
77+ flag.StringVar(&o.output, "output", "", "Output zip file path (default: <artifactId>.zip)")
78+ flag.BoolVar(&o.extract, "extract", false, "Extract archive into directory (uses base-dir)")
79+ flag.BoolVar(&o.dryRun, "dry-run", false, "Print the generated URL and exit")
80+ flag.IntVar(&o.timeout, "timeout", 60, "Download timeout in seconds")
81+ flag.BoolVar(&o.verbose, "v", false, "Verbose output")
82+ flag.BoolVar(&o.interactive, "interactive", false, "Interactive TUI mode")
83+ flag.BoolVar(&o.interactive, "i", false, "Interactive TUI mode (shorthand)")
84+ flag.BoolVar(&o.showVersion, "version", false, "Print version and exit")
85+ flag.BoolVar(&o.showVersion, "V", false, "Print version and exit (shorthand)")
86+ flag.BoolVar(&o.showLicense, "license", false, "Print licenses (app + NOTICE) and exit")
87+ flag.BoolVar(&o.showLicense, "L", false, "Print licenses (app + NOTICE) and exit (shorthand)")
88+
89+ flag.Usage = func() {
90+ fmt.Fprintf(os.Stderr, "Spring Initializr CLI (Go)\n\n")
91+ fmt.Fprintf(os.Stderr, "Usage: %s [options]\n\n", filepath.Base(os.Args[0]))
92+ fmt.Fprintf(os.Stderr, "Examples:\n")
93+ fmt.Fprintf(os.Stderr, " %s --type maven-project --language java \\\n", filepath.Base(os.Args[0]))
94+ fmt.Fprintf(os.Stderr, " --group-id com.example --artifact-id demo \\\n")
95+ fmt.Fprintf(os.Stderr, " --dependencies web,data-jpa --extract\n\n")
96+ flag.PrintDefaults()
97+ fmt.Fprintf(os.Stderr, "\nNotes:\n- Dependencies are Spring Initializr IDs (e.g. web, data-jpa, security).\n")
98+ fmt.Fprintf(os.Stderr, "- If --extract is set, the zip will be downloaded and extracted into --base-dir (defaults to artifact-id).\n")
99+ fmt.Fprintf(os.Stderr, "- Use --dry-run to just print the URL.\n")
100+ fmt.Fprintf(os.Stderr, "- Use --version or -V to print the version.\n")
101+ fmt.Fprintf(os.Stderr, "- Use --license or -L to print licenses and exit.\n")
102+ }
128103
129- return o
130- }
104+ flag.Parse()
105+
106+ // Fill derived defaults
107+ if o.baseDir == "" {
108+ o.baseDir = o.artifactID
109+ }
110+ if o.packageName == "" {
111+ o.packageName = sanitizePackage(o.groupID + "." + o.artifactID)
112+ } else {
113+ o.packageName = sanitizePackage(o.packageName)
114+ }
115+ if o.output == "" {
116+ o.output = o.artifactID + ".zip"
117+ }
131118
119+ // Normalize some shortcuts
120+ switch strings.ToLower(o.projectType) {
121+ case "maven", "maven-project":
122+ o.projectType = "maven-project"
123+ case "gradle", "gradle-project":
124+ o.projectType = "gradle-project"
125+ case "gradle-build":
126+ // as-is
127+ default:
128+ // keep as provided, server will validate
129+ }
130+
131+ return o
132+ }
132133*/
133134func run (o options ) error {
134- if o .showVersion {
135- fmt .Println (version )
136- return nil
137- }
138- if o .showLicense {
139- printLicenses ()
140- return nil
141- }
142- if o .interactive {
143- // Use the full-featured TUI if available
144- return runInteractive (o )
145- }
135+ if o .showVersion {
136+ fmt .Println (version )
137+ return nil
138+ }
139+ if o .showLicense {
140+ printLicenses ()
141+ return nil
142+ }
143+ if o .interactive {
144+ // Use the full-featured TUI if available
145+ return runInteractive (o )
146+ }
146147 if strings .ToLower (o .target ) != "zip" {
147148 return fmt .Errorf ("unsupported target '%s' (only 'zip' is supported)" , o .target )
148149 }
0 commit comments