Skip to content

Commit

Permalink
set working dir
Browse files Browse the repository at this point in the history
  • Loading branch information
iwate committed Feb 28, 2020
1 parent 65cb337 commit b05461e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Aiplugs.PoshApp/Services/Powershell/PowershellWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ private async Task TryInvokeCommand(Runspace runspace)
if (content == null)
return;

var workingDir = await _service.GetScriptDir(invokeCommand.ScriptId);
runspace.SessionStateProxy.Path.SetLocation(workingDir);
using var ps = PowerShell.Create(runspace);
ps.Streams.Error.DataAdding += (sender, args) =>
{
Expand Down
31 changes: 31 additions & 0 deletions src/Aiplugs.PoshApp/Services/ScriptsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,36 @@ public async Task RemoveScript(Repository repository, string id)
_semaphore.Release();
}
}

public async Task<string> GetScriptDir(string scriptId)
{
var splited = scriptId.Split(':');

if (splited.Length != 2)
throw new ArgumentException(nameof(scriptId));

var repositoryName = splited[0];

var scriptName = splited[1];

var repository = await GetRepository(repositoryName);

if (repository == null)
return null;

var script = await GetScript(repository, scriptName);

if (script == null)
return null;

return GetScriptDir(repository, script);
}

public string GetScriptDir(Repository repository, Script script)
{
var path = GetScriptPath(repository, script.Path);

return Path.GetDirectoryName(path);
}
}
}

0 comments on commit b05461e

Please sign in to comment.