@@ -34,7 +34,7 @@ namespace cppwinrt
3434 { " ?" , 0 , option::no_max, {}, {} },
3535 { " library" , 0 , 1 , " <prefix>" , " Specify library prefix (defaults to winrt)" },
3636 { " filter" }, // One or more prefixes to include in input (same as -include)
37- { " license" , 0 , 0 }, // Generate license comment
37+ { " license" , 0 , 1 , " [<path>] " , " Generate license comment from template file " },
3838 { " brackets" , 0 , 0 }, // Use angle brackets for #includes (defaults to quotes)
3939 { " fastabi" , 0 , 0 }, // Enable support for the Fast ABI
4040 { " ignore_velocity" , 0 , 0 }, // Ignore feature staging metadata and always include implementations
@@ -115,6 +115,40 @@ R"( local Local ^%WinDir^%\System32\WinMetadata folder
115115 settings.exclude .insert (exclude);
116116 }
117117
118+ if (settings.license )
119+ {
120+ std::string license_arg = args.value (" license" );
121+ if (license_arg.empty ())
122+ {
123+ settings.license_template = R"( // Copyright (c) Microsoft Corporation. All rights reserved.
124+ // Licensed under the MIT License.
125+ )" ;
126+ }
127+ else
128+ {
129+ std::filesystem::path template_path{ license_arg };
130+ std::ifstream template_file (absolute (template_path));
131+ if (template_file.fail ())
132+ {
133+ throw_invalid (" Cannot read license template file '" , absolute (template_path).string () + " '" );
134+ }
135+ std::string line_buf;
136+ while (getline (template_file, line_buf))
137+ {
138+ if (line_buf.empty ())
139+ {
140+ settings.license_template += " //\n " ;
141+ }
142+ else
143+ {
144+ settings.license_template += " // " ;
145+ settings.license_template += line_buf;
146+ settings.license_template += " \n " ;
147+ }
148+ }
149+ }
150+ }
151+
118152 if (settings.component )
119153 {
120154 settings.component_overwrite = args.exists (" overwrite" );
0 commit comments