Example #1
0
        private int Build(ILogger logger, BuildOrDecompileArguments arguments)
        {
            var diagnosticLogger = new BicepDiagnosticLogger(logger);
            var bicepPath        = PathHelper.ResolvePath(arguments.InputFile);

            if (arguments.OutputToStdOut)
            {
                BuildToStdout(diagnosticLogger, bicepPath);
            }
            else if (arguments.OutputDir is not null)
            {
                var outputDir = PathHelper.ResolvePath(arguments.OutputDir);
                if (!Directory.Exists(outputDir))
                {
                    throw new CommandLineException($"The specified output directory \"{outputDir}\" does not exist.");
                }

                var outputPath = Path.Combine(outputDir, Path.GetFileName(bicepPath));

                BuildToFile(diagnosticLogger, bicepPath, PathHelper.GetDefaultBuildOutputPath(outputPath));
            }
            else if (arguments.OutputFile is not null)
            {
                BuildToFile(diagnosticLogger, bicepPath, arguments.OutputFile);
            }
            else
            {
                BuildToFile(diagnosticLogger, bicepPath, PathHelper.GetDefaultBuildOutputPath(bicepPath));
            }

            // return non-zero exit code on errors
            return(diagnosticLogger.HasLoggedErrors ? 1 : 0);
        }
Example #2
0
        public int Decompile(ILogger logger, BuildOrDecompileArguments arguments)
        {
            logger.LogWarning(
                "WARNING: Decompilation is a best-effort process, as there is no guaranteed mapping from ARM JSON to Bicep.\n" +
                "You may need to fix warnings and errors in the generated bicep file(s), or decompilation may fail entirely if an accurate conversion is not possible.\n" +
                "If you would like to report any issues or inaccurate conversions, please see https://github.com/Azure/bicep/issues.");

            var diagnosticLogger = new BicepDiagnosticLogger(logger);
            var jsonPath         = PathHelper.ResolvePath(arguments.InputFile);

            if (arguments.OutputToStdOut)
            {
                return(DecompileToStdout(diagnosticLogger, jsonPath));
            }
            else if (arguments.OutputDir is not null)
            {
                var outputDir = PathHelper.ResolvePath(arguments.OutputDir);
                if (!Directory.Exists(outputDir))
                {
                    throw new CommandLineException($"The specified output directory \"{outputDir}\" does not exist.");
                }

                var outputPath = Path.Combine(outputDir, Path.GetFileName(jsonPath));

                return(DecompileToFile(diagnosticLogger, jsonPath, PathHelper.GetDefaultDecompileOutputPath(outputPath)));
            }
            else if (arguments.OutputFile is not null)
            {
                return(DecompileToFile(diagnosticLogger, jsonPath, arguments.OutputFile));
            }
            else
            {
                return(DecompileToFile(diagnosticLogger, jsonPath, PathHelper.GetDefaultDecompileOutputPath(jsonPath)));
            }
        }
Example #3
0
        public int Decompile(ILogger logger, BuildOrDecompileArguments arguments)
        {
            logger.LogWarning(CliResources.DecompilerDisclaimerMessage);
            var diagnosticLogger = new BicepDiagnosticLogger(logger);
            var jsonPath         = PathHelper.ResolvePath(arguments.InputFile);

            if (arguments.OutputToStdOut)
            {
                return(DecompileToStdout(diagnosticLogger, jsonPath));
            }
            else if (arguments.OutputDir is not null)
            {
                var outputDir = PathHelper.ResolvePath(arguments.OutputDir);
                if (!Directory.Exists(outputDir))
                {
                    throw new CommandLineException(string.Format(CliResources.DirectoryDoesNotExistFormat, outputDir));
                }

                var outputPath = Path.Combine(outputDir, Path.GetFileName(jsonPath));

                return(DecompileToFile(diagnosticLogger, jsonPath, PathHelper.GetDefaultDecompileOutputPath(outputPath)));
            }
            else if (arguments.OutputFile is not null)
            {
                return(DecompileToFile(diagnosticLogger, jsonPath, arguments.OutputFile));
            }
            else
            {
                return(DecompileToFile(diagnosticLogger, jsonPath, PathHelper.GetDefaultDecompileOutputPath(jsonPath)));
            }
        }