Skip to content

Commit

Permalink
Merge branch '10-support-automation' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
WelliSolutions committed Dec 16, 2023
2 parents b336b92 + a25b918 commit 579d6d2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
37 changes: 37 additions & 0 deletions src/CamelCaseConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2023 Lukas Benner, Thomas Weller
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Text;

namespace AASFix;

internal class CamelCaseConverter
{
internal string ToHumanReadable(string camelCase)
{
if (string.IsNullOrEmpty(camelCase)) { return camelCase; }

var builder = new StringBuilder(camelCase.Length);
foreach (var c in camelCase)
{
if (char.IsUpper(c))
{
builder.Append(' ');
}
builder.Append(c);
}

return builder.ToString();
}
}
27 changes: 22 additions & 5 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,48 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.IO.Packaging;

namespace AASFix;

public class Program
{
static void Main(string[] args)
static int Main(string[] args)
{
if (args.Length != 3)
{
Console.WriteLine($"Too few arguments. Only {args.Length} arguments given.");
PrintUsage(); return;
PrintUsage(); return (int)ReturnCode.WrongUsage;
}

if (!new[] { "--fix", "--unfix" }.Contains(args[2]))
{
Console.WriteLine($"Unknown operation: {args[2]}");
PrintUsage(); return;
PrintUsage(); return (int)ReturnCode.WrongUsage;
}

if (!File.Exists(args[0]))
{
Console.WriteLine("Input file not found. If you have spaces in your path, use quotation marks.");
return;
return (int)ReturnCode.FileError;
}

if (File.Exists(args[1]))
{
Console.WriteLine("Output file already exists. This program will not overwrite existing files.");
return;
return (int)ReturnCode.FileError;
}

new Program().Run(args[0], args[1], args[2] == "--unfix");
return (int)ReturnCode.Success;
}

private enum ReturnCode
{
Success = 0,
WrongUsage = 1,
FileError = 2,
}

readonly List<Fix> _fixes = new()
Expand Down Expand Up @@ -118,5 +127,13 @@ private static void PrintUsage()
Console.WriteLine(" --unfix : reverse the operation, i.e. break the file according the standard.");
Console.WriteLine(" This will make the output file usable with unpatched versions of AASX package explorer.");
Console.WriteLine(" The output file may not work e.g. with the Python basyx library.");
Console.WriteLine();
Console.WriteLine("Exit Codes:");
var cc = new CamelCaseConverter();
foreach (var value in Enum.GetValues<ReturnCode>())
{
var humanReadable = cc.ToHumanReadable(value.ToString());
Console.WriteLine($" {(int)value} {humanReadable}");
}
}
}

0 comments on commit 579d6d2

Please sign in to comment.