forked from x97mdr/pickles
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Pickles GUI: Generate equivalent PowerShell or Windows Console c…
…ommand line Fixes #90
- Loading branch information
Martin Gondermann
committed
Oct 4, 2018
1 parent
63e5953
commit 7de933d
Showing
7 changed files
with
316 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/Pickles/Pickles.UserInterface/CommandGeneration/CLICommandGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="CLICommandGenerator.cs" company="PicklesDoc"> | ||
// Copyright 2011 Jeffrey Cameron | ||
// Copyright 2012-present PicklesDoc team and community contributors | ||
// | ||
// | ||
// 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. | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
using System.Text; | ||
|
||
using PicklesDoc.Pickles.UserInterface.Settings; | ||
|
||
namespace PicklesDoc.Pickles.UserInterface.CommandGeneration | ||
{ | ||
public class CLICommandGenerator : CommandGeneratorBase | ||
{ | ||
protected override string GenerateSingleCommandLine( | ||
MainModel model, | ||
string outputDirectory, | ||
DocumentationFormat documentationFormat, | ||
string selectedLanguage) | ||
{ | ||
var result = new StringBuilder("pickles.exe"); | ||
result.AppendFormat(" --feature-directory=\"{0}\"", model.FeatureDirectory); | ||
result.AppendFormatIfNotEmpty(" --output-directory=\"{0}\"", outputDirectory); | ||
result.AppendFormatIfNotEmpty(" --system-under-test-name={0}", model.ProjectName); | ||
result.AppendFormatIfNotEmpty(" --system-under-test-version={0}", model.ProjectVersion); | ||
|
||
if (model.IncludeTestResults) | ||
{ | ||
result.AppendFormatIfNotEmpty(" --link-results-file=\"{0}\"", model.TestResultsFile); | ||
|
||
if (model.TestResultsFormat != TestResultsFormat.NUnit) | ||
{ | ||
result.AppendFormat(" --test-results-format={0}", model.TestResultsFormat.ToString().ToLowerInvariant()); | ||
} | ||
} | ||
|
||
result.AppendFormatIfNotEmpty(" --language={0}", selectedLanguage); | ||
|
||
if (documentationFormat != DocumentationFormat.Html) | ||
{ | ||
result.AppendFormat(" --documentation-format={0}", documentationFormat.ToString().ToLowerInvariant()); | ||
} | ||
|
||
if (model.IncludeExperimentalFeatures) | ||
{ | ||
result.Append(" --include-experimental-features"); | ||
} | ||
|
||
if (!model.EnableComments) | ||
{ | ||
result.Append(" --enableComments=false"); | ||
} | ||
|
||
result.AppendFormatIfNotEmpty(" --excludeTags=", model.ExcludeTags); | ||
result.AppendFormatIfNotEmpty(" --hideTags=", model.HideTags); | ||
|
||
return result.ToString(); | ||
} | ||
|
||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/Pickles/Pickles.UserInterface/CommandGeneration/CommandGeneratorBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="CommandGeneratorBase.cs" company="PicklesDoc"> | ||
// Copyright 2011 Jeffrey Cameron | ||
// Copyright 2012-present PicklesDoc team and community contributors | ||
// | ||
// | ||
// 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. | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
using PicklesDoc.Pickles.UserInterface.Settings; | ||
|
||
namespace PicklesDoc.Pickles.UserInterface.CommandGeneration | ||
{ | ||
public abstract class CommandGeneratorBase | ||
{ | ||
public string Generate(MainModel model) | ||
{ | ||
return (from documentationFormat in model.DocumentationFormats | ||
let outputDirectory = model.CreateDirectoryForEachOutputFormat | ||
? model.OutputDirectory + Path.DirectorySeparatorChar + documentationFormat | ||
: model.OutputDirectory | ||
let selectedLanguage = CultureInfo | ||
.GetCultures(CultureTypes.NeutralCultures) | ||
.Where(c => c.LCID == model.SelectedLanguageLcid) | ||
.Select(l => l.TwoLetterISOLanguageName) | ||
.FirstOrDefault() | ||
?.ToLowerInvariant() | ||
select this.GenerateSingleCommandLine(model, outputDirectory, documentationFormat, selectedLanguage)) | ||
.Aggregate(string.Empty, (c, n) => c + Environment.NewLine + n) | ||
.Trim(); | ||
} | ||
|
||
protected abstract string GenerateSingleCommandLine( | ||
MainModel model, | ||
string outputDirectory, | ||
DocumentationFormat documentationFormat, | ||
string selectedLanguage); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/Pickles/Pickles.UserInterface/CommandGeneration/PowerShellCommandGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="PowerShellCommandGenerator.cs" company="PicklesDoc"> | ||
// Copyright 2011 Jeffrey Cameron | ||
// Copyright 2012-present PicklesDoc team and community contributors | ||
// | ||
// | ||
// 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. | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Text; | ||
|
||
using PicklesDoc.Pickles.UserInterface.Settings; | ||
|
||
namespace PicklesDoc.Pickles.UserInterface.CommandGeneration | ||
{ | ||
public class PowerShellCommandGenerator : CommandGeneratorBase | ||
{ | ||
/// <inheritdoc /> | ||
protected override string GenerateSingleCommandLine( | ||
MainModel model, | ||
string outputDirectory, | ||
DocumentationFormat documentationFormat, | ||
string selectedLanguage) | ||
{ | ||
var result = new StringBuilder("Pickle-Features") | ||
.AppendFormat(" -FeatureDirectory \"{0}\"", model.FeatureDirectory) | ||
.AppendFormatIfNotEmpty(" -OutputDirectory \"{0}\"", outputDirectory) | ||
.AppendFormatIfNotEmpty(" -SystemUnderTestName {0}", model.ProjectName) | ||
.AppendFormatIfNotEmpty(" -SystemUnderTestVersion {0}", model.ProjectVersion); | ||
|
||
if (model.IncludeTestResults) | ||
{ | ||
result.AppendFormatIfNotEmpty(" -TestResultsFile \"{0}\"", model.TestResultsFile); | ||
|
||
if (model.TestResultsFormat != TestResultsFormat.NUnit) | ||
{ | ||
result.AppendFormat(" -TestResultsFormat {0}", model.TestResultsFormat.ToString().ToLowerInvariant()); | ||
} | ||
} | ||
|
||
if (!string.Equals(selectedLanguage, "en", StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
result.AppendFormatIfNotEmpty(" --language={0}", selectedLanguage); | ||
} | ||
|
||
if (documentationFormat != DocumentationFormat.Html) | ||
{ | ||
result.AppendFormat(" --DocumentationFormat {0}", documentationFormat.ToString()); | ||
} | ||
|
||
if (model.IncludeExperimentalFeatures) | ||
{ | ||
result.Append(" -IncludeExperimentalFeatures"); | ||
} | ||
|
||
if (!model.EnableComments) | ||
{ | ||
result.Append(" -EnableComments false"); | ||
} | ||
|
||
result.AppendFormatIfNotEmpty(" -ExcludeTags ", model.ExcludeTags); | ||
result.AppendFormatIfNotEmpty(" -HideTags ", model.HideTags); | ||
|
||
return result.ToString(); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Pickles/Pickles.UserInterface/CommandGeneration/StringBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="StringBuilderExtensions.cs" company="PicklesDoc"> | ||
// Copyright 2011 Jeffrey Cameron | ||
// Copyright 2012-present PicklesDoc team and community contributors | ||
// | ||
// | ||
// 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. | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
using System.Text; | ||
|
||
namespace PicklesDoc.Pickles.UserInterface.CommandGeneration | ||
{ | ||
public static class StringBuilderExtensions | ||
{ | ||
public static StringBuilder AppendFormatIfNotEmpty(this StringBuilder stringBuilder, string format, string value) | ||
{ | ||
return string.IsNullOrWhiteSpace(value) | ||
? stringBuilder | ||
: stringBuilder.AppendFormat(format, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters