/// <summary> /// Returns the path of the unique project file in the current directory (if any) /// </summary> /// <returns></returns> /// <exception cref="CommandException"></exception> protected string GetCurrentProjectFilePath() { var list = Directory.EnumerateFiles(Directory.GetCurrentDirectory(), $"*{OeBuilderConstants.OeProjectExtension}", SearchOption.TopDirectoryOnly).ToList(); if (list.Count == 0) { var oeDir = OeBuilderConstants.GetProjectDirectory(Directory.GetCurrentDirectory()); if (Directory.Exists(oeDir)) { list = Directory.EnumerateFiles(oeDir, $"*{OeBuilderConstants.OeProjectExtension}", SearchOption.TopDirectoryOnly).ToList(); } if (list.Count == 0) { throw new CommandException($"No project file {OeBuilderConstants.OeProjectExtension.PrettyQuote()} found in the current folder {Directory.GetCurrentDirectory().PrettyQuote()} nor the {OeBuilderConstants.OeProjectDirectory} directory. Initialize a new project file using the command: {typeof(ProjectInitCommand).GetFullCommandLine<MainCommand>().PrettyQuote()}."); } if (list.Count > 1) { throw new CommandException($"Ambiguous project, found {list.Count} project files in {OeBuilderConstants.OeProjectDirectory.PrettyQuote()}, specify the project file to use in the command line."); } } if (list.Count > 1) { throw new CommandException($"Ambiguous project, found {list.Count} project files in the current folder, specify the project file to use in the command line."); } return(list.First()); }
protected override int ExecuteCommand(CommandLineApplication app, IConsole console) { var directory = ProjectDirectory ?? Directory.GetCurrentDirectory(); if (Directory.EnumerateFiles(directory, $"*{OeBuilderConstants.OeProjectExtension}", SearchOption.TopDirectoryOnly).Any()) { OeProject.SaveXsd(directory); } else { directory = OeBuilderConstants.GetProjectDirectory(directory); if (Directory.EnumerateFiles(directory, $"*{OeBuilderConstants.OeProjectExtension}", SearchOption.TopDirectoryOnly).Any()) { OeProject.SaveXsd(directory); } else { directory = null; } } if (!string.IsNullOrEmpty(directory)) { Log.Info($"The file {Path.Combine(directory, OeProject.XsdName)} has been updated with the latest version."); } return(0); }
protected override string GetLogFilePathDefaultValue() { if (Directory.Exists(OeBuilderConstants.GetProjectDirectory(Directory.GetCurrentDirectory()))) { return(Path.Combine(OeBuilderConstants.GetProjectDirectoryLocal(Directory.GetCurrentDirectory()), "logs", "sakoe.log")); } return(Path.Combine(Directory.GetCurrentDirectory(), "sakoe.log")); }
protected override int ExecuteCommand(CommandLineApplication app, IConsole console) { if (string.IsNullOrEmpty(SourceDirectory)) { SourceDirectory = Directory.GetCurrentDirectory(); Log.Trace?.Write($"Using current directory to initialize the project: {SourceDirectory.PrettyQuote()}."); } SourceDirectory = SourceDirectory.ToAbsolutePath().ToCleanPath(); if (string.IsNullOrEmpty(ProjectName)) { ProjectName = Path.GetFileName(SourceDirectory); Log.Info($"Using directory name for the project name: {ProjectName.PrettyQuote()}."); } var projectDirectory = IsLocalProject ? OeBuilderConstants.GetProjectDirectoryLocal(SourceDirectory) : OeBuilderConstants.GetProjectDirectory(SourceDirectory); if (Utils.CreateDirectoryIfNeeded(projectDirectory, FileAttributes.Hidden)) { Log.Info($"Created project directory: {projectDirectory.PrettyQuote()}."); } Log.Trace?.Write("Generating a default project."); var project = OeProject.GetStandardProject(); var projectFilePath = Path.Combine(projectDirectory, $"{ProjectName}{OeBuilderConstants.OeProjectExtension}"); if (File.Exists(projectFilePath)) { if (Force) { File.Delete(projectFilePath); } else { throw new CommandValidationException($"The project file already exists, delete it first: {projectFilePath.PrettyQuote()}."); } } Log.Info($"Creating Openedge project file: {projectFilePath.PrettyQuote()}."); project.Save(projectFilePath); Log.Info($"Project created: {projectFilePath.PrettyQuote()}."); HelpWriter.WriteOnNewLine(null); HelpWriter.WriteSectionTitle("IMPORTANT README:"); HelpWriter.WriteOnNewLine(@" The project file created (" + OeBuilderConstants.OeProjectExtension + @") is defined in XML format and has a provided XML schema definition file (" + OeProject.XsdName + @"). The project XML schema is fully documented and should be used to enable intellisense in your favorite editor. Example of xml editors with out-of-the-box intellisense (autocomplete) features for xml: - Progress Developer studio (eclipse) - Visual studio - Most jetbrain IDE Drag and drop the created " + OeBuilderConstants.OeProjectExtension + @" file into the editor of your choice and start configuring your build. The file " + Path.Combine(OeBuilderConstants.GetProjectDirectory(""), $"{ProjectName}{OeBuilderConstants.OeProjectExtension}").PrettyQuote() + @" should be versioned in your source repository to allow anyone who clones your application to build it. The file " + OeProject.XsdName.PrettyQuote() + @", however, should not be versioned with your application because it depends on the version of this tool (sakoe). If this tool is updated, use the command " + typeof(ProjectUpdateCommand).GetFullCommandLine <MainCommand>().PrettyQuote() + @" to update the " + OeProject.XsdName.PrettyQuote() + @" to the latest version. If you need to have a project file containing build configurations specific to your local machine, you can use the option " + (GetCommandOptionFromPropertyName(nameof(IsLocalProject))?.Template ?? "").PrettyQuote() + @". This will create the project file into the directory " + OeBuilderConstants.GetProjectDirectoryLocal("").PrettyQuote() + @" which should NOT be versioned. For git repositories, use the command " + typeof(ProjectGitignoreCommand).GetFullCommandLine <MainCommand>().PrettyQuote() + @" to set up your .gitignore file for sakoe projects."); HelpWriter.WriteOnNewLine(null); return(0); }