Skip to content

Commit

Permalink
Merge pull request #12 from OctopusDeploy/core/core-utilities-ref-rem…
Browse files Browse the repository at this point in the history
…oval

Removed Octopus.CoreUtilities reference
  • Loading branch information
michaelongso committed Nov 8, 2022
2 parents 35df8a2 + 25e09ac commit 83bda77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Octopus.CoreUtilities" Version="1.1.2" />
<PackageReference Include="Sprache" Version="2.3.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Octopus.CoreUtilities.Extensions;
using Sprache;

namespace Octopus.CoreParsers.Hcl
Expand Down Expand Up @@ -163,7 +162,7 @@ public virtual string OriginalName
public virtual HclElement Child
{
get => Children?.FirstOrDefault();
set => Children = value?.ToEnumerable();
set => Children = value is not null ? new[] { value } : null;
}

/// <summary>
Expand All @@ -186,8 +185,8 @@ public virtual string ToString(bool naked, int indent)
var separator = indent == -1 ? ", " : "\n";

return indentString + OriginalName +
ProcessedValue?.Map(a => " \"" + EscapeQuotes(a) + "\"") +
Type?.Map(a => " \"" + EscapeQuotes(a) + "\"") +
RunIfNotNull(ProcessedValue, a => " \"" + EscapeQuotes(a) + "\"") +
RunIfNotNull(Type, a => " \"" + EscapeQuotes(a) + "\"") +
" {" + lineBreak +
string.Join(separator,
Children?.Select(child => child.ToString(nextIndent)) ?? Enumerable.Empty<string>()) +
Expand Down Expand Up @@ -254,11 +253,16 @@ public override int GetHashCode()
return hash;
}

protected string EscapeQuotes(string input)
protected static string EscapeQuotes(string input)
{
if (input == null) throw new ArgumentException("input can not be null");

return HclParser.StringLiteralQuoteContentReverse.Parse(input);
}

private static TResult RunIfNotNull<TSource, TResult>(TSource input, Func<TSource, TResult> command)
{
return input is null ? default : command(input);
}
}
}

0 comments on commit 83bda77

Please sign in to comment.