• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AnderssonPeter / PowerType / 5282352643

pending completion
5282352643

push

github

AnderssonPeter
Construct a Uri builder in a different way to support linux file paths.

Resolves: #37

308 of 466 branches covered (66.09%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

661 of 904 relevant lines covered (73.12%)

60.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/PowerType/EnablePowerTypePredictor.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Diagnostics;
4
using System.IO;
5
using System.Linq;
6
using System.Management.Automation;
7
using System.Management.Automation.Subsystem;
8
using System.Management.Automation.Subsystem.Prediction;
9
using System.Reflection;
10
using System.Text;
11

12
namespace PowerType;
13

14
/// <summary>
15
/// <para type="synopsis">Cmdlet to enable PowerType Predictor and start receiving suggestions</para>
16
/// <para type="description">Use this cmdlet to enable PowerType Predictor and start receiving suggestions</para>
17
/// </summary>
18
[Cmdlet("Enable", "PowerType"), OutputType(typeof(bool))]
19
public class EnablePowerTypePredictor : PowerTypeCmdlet
20
{
21
    private const string enableStatement = "Set-PSReadLineOption -PredictionSource Plugin";
22

23
    /// <summary>
24
    /// <para type="description">Indicates whether the user would like to receive output. </para>
25
    /// </summary>
26
    [Parameter(Mandatory = false, HelpMessage = "Indicates whether the user would like to receive output.")]
27
    public SwitchParameter PassThru { get; set; }
×
28

29
    /// <summary>
30
    /// <para type="description">Lazy load prediction dictionaries. </para>
31
    /// </summary>
32
    [Parameter(Mandatory = false, HelpMessage = "Lazy load prediction dictionaries.")]
33
    public SwitchParameter LazyLoad { get; set; }
×
34

35
    /// <summary>
36
    /// <para type="description">List of dictionaries to load, if not provided all are loaded. </para>
37
    /// </summary>
38
    [Parameter(Mandatory = false, HelpMessage = "List of dictionaries to load, if not provided all are loaded.")]
39
    public string[]? DictionariesToLoad { get; set; }
×
40

41
    /// <summary>
42
    /// <para type="description">List of dictionaries to load, if not provided all are loaded. </para>
43
    /// </summary>
44
    [Parameter(Mandatory = false, HelpMessage = "List of dictionaries to load, if not provided all are loaded.")]
45
    public string[]? DictionariesToIgnore { get; set; }
×
46

47
    /// <inheritdoc/>
48
    protected override void ProcessRecord()
49
    {
50
        var scriptToRun = new StringBuilder();
×
51
        scriptToRun.Append(enableStatement);
×
52

53
        InvokeCommand.InvokeScript(scriptToRun.ToString());
×
54

55
        var currentWorkingDirectoryProvider = new CurrentWorkingDirectoryProvider(SessionState);
×
56
        var predictor = new PowerTypePredictor(currentWorkingDirectoryProvider, GetDictionaries());
×
57
        SubsystemManager.RegisterSubsystem<ICommandPredictor, PowerTypePredictor>(predictor);
×
58
        PowerTypePredictor.Instance = predictor;
×
59
        if (PassThru.IsPresent)
×
60
        {
61
            WriteObject(true);
×
62
        }
63
    }
×
64

65
    public static string AssemblyPath
66
    {
67
        get
68
        {
69
            string codeBase = Assembly.GetExecutingAssembly().Location;
×
70
            UriBuilder uri = new();
×
71
            uri.Scheme = "file://";
×
72
            uri.Path = codeBase;
×
73
            return Uri.UnescapeDataString(uri.Path);
×
74
        }
75
    }
76

77
    public static string ModuleDirectory => Path.GetDirectoryName(AssemblyPath) ?? throw new Exception("Failed to get ModuleDirectory");
×
78

79
    public static string DictionariesDirectory => Path.Combine(ModuleDirectory, "Dictionaries");
×
80

81
    private IEnumerable<string> GetDictionaries()
82
    {
83
        foreach (var dictionaryPath in Directory.EnumerateFiles(DictionariesDirectory, "*.ps1"))
×
84
        {
85
            var filename = Path.GetFileNameWithoutExtension(dictionaryPath);
×
86
            if (DictionariesToLoad != null)
×
87
            {
88
                if (DictionariesToLoad.Contains(filename, StringComparer.OrdinalIgnoreCase))
×
89
                {
90
                    yield return filename;
×
91
                }
92
            }
93
            else if (DictionariesToIgnore != null)
×
94
            {
95
                if (!DictionariesToIgnore.Contains(filename, StringComparer.OrdinalIgnoreCase))
×
96
                {
97
                    yield return filename;
×
98
                }
99
            }
100
            else
101
            {
102
                yield return dictionaryPath;
×
103
            }
104
        }
105
    }
×
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc