Skip to content

Commit

Permalink
add edit skill command
Browse files Browse the repository at this point in the history
  • Loading branch information
csc530 committed Aug 1, 2024
1 parent a437cb5 commit b32ce16
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 46 deletions.
20 changes: 20 additions & 0 deletions .run/edit skill.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="edit skill" type="DotNetProject" factoryName=".NET Project" folderName="edit">
<option name="EXE_PATH" value="$PROJECT_DIR$/Resumer/bin/Debug/net8.0/Resumer.exe" />
<option name="PROGRAM_PARAMETERS" value="edit skill" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Resumer/bin/Debug/net8.0" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/Resumer/Resumer.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="net8.0" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
95 changes: 49 additions & 46 deletions Resumer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public static void AppConfiguration(IConfigurator config)
.WithAlias("school")
.WithAlias("degree")
.WithDescription("edit an education's details");
edit.AddCommand<EditSkillCommand>("skill")
.WithAlias("s")
.WithDescription("edit a skill's details");
});

config.AddBranch<DeleteCommandSettings>("delete", delete =>
Expand Down Expand Up @@ -147,52 +150,52 @@ public static void AppConfiguration(IConfigurator config)


config.AddBranch<OutputCommandSettings>("get", get =>
{
get.SetDescription("get job information from database");
get.AddCommand<GetConfigCommand>("config")
.WithAlias("configuration")
.WithAlias("conf")
.WithAlias("setting")
.WithDescription("get app's current configuration settings")
.WithAlias("settings");
get.AddCommand<GetSkillCommand>("skill")
.WithAlias("s")
.WithDescription("list skills")
.WithAlias("skills");
get.AddCommand<GetCompanyCommand>("company")
.WithAlias("c")
.WithDescription("list companies")
.WithAlias("companies")
.WithDescription("list companies you've worked for");
get.AddCommand<GetJobCommand>("job")
.WithAlias("jobs")
.WithDescription("list jobs")
.WithAlias("j");
get.AddCommand<GetProfileCommand>("profile")
.WithAlias("user")
.WithAlias("u")
.WithAlias("users")
.WithDescription("list user profiles")
.WithAlias("profiles");
get.AddCommand<GetProjectCommand>("project")
.WithDescription("list projects")
.WithAlias("p")
.WithAlias("projects");
get.AddCommand<GetTypstTemplateCommand>("template")
.WithAlias("t")
.WithAlias("templates")
.WithDescription("list typst templates");
get.AddCommand<GetEducationCommand>("education")
.WithAlias("edu")
.WithAlias("educations")
.WithAlias("schools")
.WithAlias("school")
.WithAlias("degree")
.WithDescription("list education");
})
.WithAlias("g")
.WithAlias("list")
.WithAlias("ls");
{
get.SetDescription("get job information from database");
get.AddCommand<GetConfigCommand>("config")
.WithAlias("configuration")
.WithAlias("conf")
.WithAlias("setting")
.WithDescription("get app's current configuration settings")
.WithAlias("settings");
get.AddCommand<GetSkillCommand>("skill")
.WithAlias("s")
.WithDescription("list skills")
.WithAlias("skills");
get.AddCommand<GetCompanyCommand>("company")
.WithAlias("c")
.WithDescription("list companies")
.WithAlias("companies")
.WithDescription("list companies you've worked for");
get.AddCommand<GetJobCommand>("job")
.WithAlias("jobs")
.WithDescription("list jobs")
.WithAlias("j");
get.AddCommand<GetProfileCommand>("profile")
.WithAlias("user")
.WithAlias("u")
.WithAlias("users")
.WithDescription("list user profiles")
.WithAlias("profiles");
get.AddCommand<GetProjectCommand>("project")
.WithDescription("list projects")
.WithAlias("p")
.WithAlias("projects");
get.AddCommand<GetTypstTemplateCommand>("template")
.WithAlias("t")
.WithAlias("templates")
.WithDescription("list typst templates");
get.AddCommand<GetEducationCommand>("education")
.WithAlias("edu")
.WithAlias("educations")
.WithAlias("schools")
.WithAlias("school")
.WithAlias("degree")
.WithDescription("list education");
})
.WithAlias("g")
.WithAlias("list")
.WithAlias("ls");
}

public static string TempPath { get; } = Path.GetTempPath() + "resumer" + Path.DirectorySeparatorChar;
Expand Down
41 changes: 41 additions & 0 deletions Resumer/cli/commands/edit/EditSkillCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Resumer.models;
using Spectre.Console;
using Spectre.Console.Cli;
using Command = Spectre.Console.Cli.Command;

namespace Resumer.cli.commands.edit;

public class EditSkillCommand: Command
{
public override int Execute(CommandContext context)
{
var db = new ResumeContext();

var skill = AnsiConsole.Prompt(new SelectionPrompt<Skill>()
.Title("Select skill to edit")
.AddChoices(db.Skills.OrderBy(s => s.Name))
.WrapAround()
.PageSize(10)
);
db.Skills.Update(skill);
AnsiConsole.WriteLine($"Editing: {skill}");

var name = AnsiConsole.Prompt(new TextPrompt<string>("Name:").DefaultValue(skill.Name));
var type = AnsiConsole.Prompt(new TextPrompt<SkillType>("Type (hard/soft):").DefaultValue(skill.Type));


// because skill.name is the PK and it's not a [foreign key assoc.](https://stackoverflow.com/questions/5281974/code-first-independent-associations-vs-foreign-key-associations/5282275#5282275)
// tl;dr remove and insert to update 🙄
if(!skill.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))
{
db.Skills.Remove(skill);
db.Skills.Add(new Skill(name, type));
}
else
skill.Type = type;

db.SaveChanges();

return CommandOutput.Success("Skill updated successfully");
}
}

0 comments on commit b32ce16

Please sign in to comment.