static void ValidateAndApplyDefaults(Options options) { if (options.Exclude.Any()) { throw new CommandLineException("`exclude` is obsolete. Use `exclude-directories`."); } if (options.Header != null && string.IsNullOrWhiteSpace(options.Header)) { throw new CommandLineException("Empty Header is not allowed."); } if (options.UrlPrefix != null && string.IsNullOrWhiteSpace(options.UrlPrefix)) { throw new CommandLineException("Empty UrlPrefix is not allowed."); } if (options.TargetDirectory == null) { options.TargetDirectory = Environment.CurrentDirectory; if (!GitRepoDirectoryFinder.IsInGitRepository(options.TargetDirectory)) { throw new CommandLineException($"The current directory does no exist with a .git repository. Pass in a target directory instead. Current directory: {options.TargetDirectory}"); } } else { if (!Directory.Exists(options.TargetDirectory)) { throw new CommandLineException("target-directory does not exist."); } options.TargetDirectory = Path.GetFullPath(options.TargetDirectory); } if (options.TocLevel <= 0) { throw new CommandLineException("toc-level must be positive."); } if (options.MaxWidth <= 0) { throw new CommandLineException("max-width must be positive."); } ValidateItems("exclude", options.ExcludeDirectories); ValidateItems("exclude-markdown-directories", options.ExcludeMarkdownDirectories); ValidateItems("exclude-snippet-directories", options.ExcludeSnippetDirectories); ValidateItems("toc-excludes", options.TocExcludes); ValidateItems("urls-as-snippets", options.UrlsAsSnippets); }
static void ApplyDefaults(Options options) { if (options.TargetDirectory == null) { options.TargetDirectory = Environment.CurrentDirectory; if (!GitRepoDirectoryFinder.IsInGitRepository(options.TargetDirectory)) { throw new CommandLineException($"The current directory does no exist with a .git repository. Pass in a target directory instead. Current directory: {options.TargetDirectory}"); } } else { options.TargetDirectory = Path.GetFullPath(options.TargetDirectory); } }