11using System ;
22using System . CommandLine ;
3+ using System . Reflection . Metadata . Ecma335 ;
34using System . Threading . Tasks ;
45
56namespace Nickvision . FlatpakGenerator ;
@@ -24,7 +25,17 @@ public static async Task<int> Main(string[] args)
2425 {
2526 "-d"
2627 } ,
27- DefaultValueFactory = r => 8
28+ DefaultValueFactory = r => 10
29+ } ,
30+ new Option < string > ( "--freedesktop" )
31+ {
32+ Description = "The FreeDesktop SDK version to target" ,
33+ Required = true ,
34+ Aliases =
35+ {
36+ "-f"
37+ } ,
38+ DefaultValueFactory = r => "25.08"
2839 } ,
2940 new Option < bool > ( "--run-as-user" )
3041 {
@@ -55,7 +66,17 @@ public static async Task<int> Main(string[] args)
5566 {
5667 "-d"
5768 } ,
58- DefaultValueFactory = r => 8
69+ DefaultValueFactory = r => 10
70+ } ,
71+ new Option < string > ( "--freedesktop" )
72+ {
73+ Description = "The FreeDesktop SDK version to target" ,
74+ Required = true ,
75+ Aliases =
76+ {
77+ "-f"
78+ } ,
79+ DefaultValueFactory = r => "25.08"
5980 } ,
6081 new Option < string > ( "--output" )
6182 {
@@ -96,16 +117,51 @@ public static async Task<int> Main(string[] args)
96117 } ;
97118 checkCommand . SetAction ( async x =>
98119 {
99- await FlatpakSourcesGenerator . CheckRuntimeAsync ( "org.freedesktop.Sdk//24.08" , x . GetValue < bool > ( "--run-as-user" ) ) ;
100- await FlatpakSourcesGenerator . CheckRuntimeAsync ( $ "org.freedesktop.Sdk.Extension.dotnet{ x . GetRequiredValue < int > ( "--dotnet" ) } //24.08", x . GetValue < bool > ( "--run-as-user" ) ) ;
120+ if ( ! IsDotnetVersionValid ( x . GetValue < int > ( "--dotnet" ) ) )
121+ {
122+ Console . Error . WriteLine ( "[Error] Invalid .NET version. Supported versions are 8, 9, and 10." ) ;
123+ return ;
124+ }
125+ if ( ! IsFreedesktopVersionValid ( x . GetValue < string > ( "--freedesktop" ) , x . GetValue < int > ( "--dotnet" ) ) )
126+ {
127+ Console . Error . WriteLine ( "[Error] Invalid FreeDesktop version for the specified .NET version." ) ;
128+ return ;
129+ }
130+ await FlatpakSourcesGenerator . CheckRuntimeAsync ( $ "org.freedesktop.Sdk//{ x . GetValue < string > ( "--freedesktop" ) } ", x . GetValue < bool > ( "--run-as-user" ) ) ;
131+ await FlatpakSourcesGenerator . CheckRuntimeAsync ( $ "org.freedesktop.Sdk.Extension.dotnet{ x . GetRequiredValue < int > ( "--dotnet" ) } //{ x . GetValue < string > ( "--freedesktop" ) } ", x . GetValue < bool > ( "--run-as-user" ) ) ;
101132 } ) ;
102133 generateCommand . SetAction ( async x =>
103134 {
104- var sources = await FlatpakSourcesGenerator . GenerateSourcesAsync ( x . GetRequiredValue < string > ( "--input" ) , x . GetRequiredValue < int > ( "--dotnet" ) , x . GetValue < string > ( "--temp" ) , x . GetValue < bool > ( "--self-contained" ) , x . GetValue < bool > ( "--run-as-user" ) ) ;
135+ if ( ! IsDotnetVersionValid ( x . GetValue < int > ( "--dotnet" ) ) )
136+ {
137+ Console . Error . WriteLine ( "[Error] Invalid .NET version. Supported versions are 8, 9, and 10." ) ;
138+ return ;
139+ }
140+ if ( ! IsFreedesktopVersionValid ( x . GetValue < string > ( "--freedesktop" ) , x . GetValue < int > ( "--dotnet" ) ) )
141+ {
142+ Console . Error . WriteLine ( "[Error] Invalid FreeDesktop version for the specified .NET version." ) ;
143+ return ;
144+ }
145+ var sources = await FlatpakSourcesGenerator . GenerateSourcesAsync ( x . GetRequiredValue < string > ( "--input" ) , x . GetRequiredValue < int > ( "--dotnet" ) , x . GetRequiredValue < string > ( "--freedesktop" ) , x . GetValue < string > ( "--temp" ) , x . GetValue < bool > ( "--self-contained" ) , x . GetValue < bool > ( "--run-as-user" ) ) ;
105146 await FlatpakSourcesGenerator . WriteSourcesFileAsync ( sources , x . GetValue < string > ( "--output" ) ) ;
106147 } ) ;
107148 rootCommand . Subcommands . Add ( checkCommand ) ;
108149 rootCommand . Subcommands . Add ( generateCommand ) ;
109150 return await rootCommand . Parse ( args ) . InvokeAsync ( ) ;
110151 }
152+
153+ private static bool IsDotnetVersionValid ( int dotnetVersion ) => dotnetVersion >= 8 && dotnetVersion <= 10 ;
154+
155+ private static bool IsFreedesktopVersionValid ( string ? freedesktopVersion , int dotnetVersion )
156+ {
157+ if ( freedesktopVersion == "24.08" )
158+ {
159+ return dotnetVersion != 8 ;
160+ }
161+ else if ( freedesktopVersion == "25.08" )
162+ {
163+ return true ;
164+ }
165+ return false ;
166+ }
111167}
0 commit comments