Beispiel #1
0
        public bool GenerateSource(ClassMetaInfo classMetaInfo)
        {
            Console.WriteLine("Generating source file.");

            var sourceTemplate = GetTemplate("SourceTemplate.cpp");
            var source         = FillTemplateWithClassMetaInfo(sourceTemplate, classMetaInfo);

            return(CreateFile(source, $"src/{classMetaInfo.Location}", $"{classMetaInfo.ClassName.ToLower()}.cpp"));
        }
Beispiel #2
0
 private string FillTemplateWithClassMetaInfo(string template, ClassMetaInfo classMetaInfo)
 {
     return(template.Replace("CLASSNAMECAPS", classMetaInfo.ClassName.ToUpper())
            .Replace("CLASSNAMELOWER", classMetaInfo.ClassName.ToLower())
            .Replace("NAMESPACECAPS", classMetaInfo.Namespace.ToUpper())
            .Replace("CLASSNAME", classMetaInfo.ClassName)
            .Replace("NAMESPACE", classMetaInfo.Namespace)
            .Replace("LOCATION", classMetaInfo.Location));
 }
Beispiel #3
0
        public bool GenerateHeader(ClassMetaInfo classMetaInfo)
        {
            Console.WriteLine("Generating header file.");

            var headerTemplate = GetTemplate("HeaderTemplate.hpp");
            var header         = FillTemplateWithClassMetaInfo(headerTemplate, classMetaInfo);

            return(CreateFile(header, $"include/{classMetaInfo.Location}", $"{classMetaInfo.ClassName.ToLower()}.hpp"));
        }
        static void AddClassCommand(CommandLineApplication app)
        {
            app.Command("class", (command) =>
            {
                command.Description = "Generate a full class, i.e. header and source file.";
                command.HelpOption("-?|-h|--help");

                var locationOption = command
                    .Option("-l|--location", "The folder in which the class is put, NOT prepended with 'include/' or 'src/'.", CommandOptionType.SingleValue)
                    .IsRequired();

                var namespaceOption = command
                    .Option("-n|--namespace", "The namespace of the class.", CommandOptionType.SingleValue)
                    .IsRequired();

                var classNameOption = command
                    .Option("-c|--classname", "The name of the class.", CommandOptionType.SingleValue)
                    .IsRequired();
                
                var headerOnlyOption = command
                    .Option("-h|--header-only", "Only generate header file.", CommandOptionType.NoValue);

                command.OnExecute(() =>
                {
                    var classMetaInfo = new ClassMetaInfo(
                        locationOption.Value(),
                        classNameOption.Value(),
                        namespaceOption.Value()
                    );

                    var filesystem = new Filesystem();
                    var classGenerator = new ClassGenerator(filesystem);

                    var success = classGenerator.GenerateHeader(classMetaInfo);
                    if(success && !headerOnlyOption.HasValue())
                        classGenerator.GenerateSource(classMetaInfo);

                    return 0;
                });
            });
        }