Skip to content

Commit d5e6e11

Browse files
committed
Improve the defaults of necessary generation options to improve accessibility.
1 parent b2b5567 commit d5e6e11

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

src/CLI/Generator.cs

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,29 @@ void SetupTargetTriple()
7474

7575
public bool ValidateOptions(List<string> messages)
7676
{
77+
if (options.HeaderFiles.Count == 0)
78+
{
79+
messages.Add("No source header file has been given to generate bindings from.");
80+
return false;
81+
}
82+
7783
if (!options.Platform.HasValue)
7884
options.Platform = GetCurrentPlatform();
7985

86+
if (string.IsNullOrEmpty(options.OutputDir))
87+
{
88+
options.OutputDir = Path.Combine(Directory.GetCurrentDirectory(), "gen");
89+
}
90+
91+
var dir = Path.GetDirectoryName(options.HeaderFiles.First());
92+
var moduleName = new DirectoryInfo(dir).Name;
93+
94+
if (string.IsNullOrEmpty(options.OutputFileName))
95+
options.OutputFileName = moduleName;
96+
97+
if (string.IsNullOrEmpty(options.OutputNamespace))
98+
options.OutputNamespace = moduleName;
99+
80100
if (Platform.IsWindows && options.Platform != TargetPlatform.Windows)
81101
{
82102
messages.Add("Cannot create bindings for a platform other that Windows from a Windows host.");
@@ -105,36 +125,6 @@ public bool ValidateOptions(List<string> messages)
105125
return false;
106126
}
107127

108-
if (options.HeaderFiles.Count == 0)
109-
{
110-
messages.Add("No source header file has been given to generate bindings from.");
111-
return false;
112-
}
113-
114-
if (string.IsNullOrEmpty(options.OutputNamespace))
115-
{
116-
messages.Add("Output namespace not specified (see --outputnamespace option).");
117-
return false;
118-
}
119-
120-
if (string.IsNullOrEmpty(options.OutputFileName))
121-
{
122-
messages.Add("Output directory not specified (see --output option).");
123-
return false;
124-
}
125-
126-
if (string.IsNullOrEmpty(options.InputLibraryName) && !options.CheckSymbols)
127-
{
128-
messages.Add("Input library name not specified and check symbols option not enabled.\nEither set the input library name or the check symbols flag.");
129-
return false;
130-
}
131-
132-
if (string.IsNullOrEmpty(options.InputLibraryName) && options.CheckSymbols && options.Libraries.Count == 0)
133-
{
134-
messages.Add("Input library name not specified and check symbols is enabled but no libraries were given.\nEither set the input library name or add at least one library.");
135-
return false;
136-
}
137-
138128
SetupTargetTriple();
139129

140130

0 commit comments

Comments
 (0)