Skip to content

Commit

Permalink
Add -Cleanup flag to Get-JumpStatus. Move todo list from source to Re…
Browse files Browse the repository at this point in the history
…adme
  • Loading branch information
Sergei Vorobev committed Feb 6, 2014
1 parent 5ca4258 commit 5e4fca6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
5 changes: 5 additions & 0 deletions Jump.Location/CommandController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ orderby record.Weight descending
select record;
}

public bool RemoveRecord(IRecord record)
{
return database.Remove(record);
}

public void PrintStatus()
{
foreach (var record in GetOrderedRecords())
Expand Down
6 changes: 6 additions & 0 deletions Jump.Location/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface IDatabase
IEnumerable<IRecord> Records { get; }
void Add(string fullPath);
void Add(IRecord record);
bool Remove(IRecord record);
IRecord GetByFullName(string fullName);
}

Expand All @@ -27,6 +28,11 @@ public void Add(IRecord record)
records.Add(record);
}

public bool Remove(IRecord record)
{
return records.Remove(record);
}

public IRecord GetByFullName(string fullName)
{
var record = records.FirstOrDefault(x => x.FullName == fullName);
Expand Down
30 changes: 30 additions & 0 deletions Jump.Location/GetJumpStatusCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Jump.Location
{
using System.IO;

[Cmdlet("Get", "JumpStatus", DefaultParameterSetName = "Query")]
public class GetJumpStatusCommand : PSCmdlet
{
Expand All @@ -21,14 +23,42 @@ public class GetJumpStatusCommand : PSCmdlet
[Parameter(ParameterSetName = "Query", HelpMessage = "Includes all results, even if the weight is negative.")]
public SwitchParameter All { get; set; }

[Parameter(ParameterSetName = "Cleanup", HelpMessage = "Remove obsolete(not existing on the file system) records from DB.")]
public SwitchParameter Cleanup { get; set; }

protected override void ProcessRecord()
{

if (Cleanup.IsPresent)
{
DoCleanup();
return;
}

if (All || Query == null || Query.Length == 0)
ProcessSearch(Controller.GetOrderedRecords(All));
else
ProcessSearch(Controller.GetMatchesForSearchTerm(Query));
}

private const string FileSystemProvider = @"Microsoft.PowerShell.Core\FileSystem";
private void DoCleanup()
{
bool needsToSave = false;
foreach (IRecord record in Controller.GetOrderedRecords(true))
{
if (record.Provider == FileSystemProvider && !Directory.Exists(record.Path))
{
Controller.RemoveRecord(record);
needsToSave = true;
}
}
if (needsToSave)
{
Controller.Save();
}
}

private void ProcessSearch(IEnumerable<IRecord> records)
{
if (Save)
Expand Down
19 changes: 4 additions & 15 deletions Jump.Location/JumpLocationCommand.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace Jump.Location
namespace Jump.Location
{
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

[Cmdlet("Jump", "Location", DefaultParameterSetName = "Query")]
public class JumpLocationCommand : PSCmdlet
Expand All @@ -27,16 +26,6 @@ private static string GetResultPath(IRecord record)
return candidate;
}

/*
* x1. Save manipulated jumpstat values
* x2. -Query switch for returning first string
* 3. Local search. `j . blah` will only match dirs under cwd. Using `.` will also search outside the DB.
* 4. -Purge (not terribly high priority)
* 5. Better PS documentation
* x6. jumpstat -First, for returning just the first
* x7. Negative Weight removes from the gene pool
*/

[Parameter(ParameterSetName = "Query", ValueFromRemainingArguments = true)]
public string[] Query { get; set; }

Expand Down
5 changes: 5 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ From root directory:

In directory `Build` you will have local build of module.

TODO
----------
1. Local search. `j . blah` will only match dirs under cwd. Using `.` will also search outside the DB.
2. Better PS documentation

References
----------
1. [old releases][4].
Expand Down

0 comments on commit 5e4fca6

Please sign in to comment.