Skip to content

Commit

Permalink
#76: Rename new platform specific stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
Taitava committed Oct 21, 2021
1 parent b5f885e commit 997c2be
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/Migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {newShellCommandConfiguration, ShellCommandConfiguration} from "./setting
export async function RunMigrations(plugin: ShellCommandsPlugin) {
let save = MigrateCommandsToShellCommands(plugin);
save ||= EnsureShellCommandsHaveAllFields(plugin);
save ||= MigrateShellCommandToShellCommands(plugin);
save ||= MigrateShellCommandToPlatforms(plugin);
if (save) {
// Only save if there were changes to configuration.
console.log("Saving migrations...")
Expand Down Expand Up @@ -80,17 +80,17 @@ function EnsureShellCommandsHaveAllFields(plugin: ShellCommandsPlugin) {
return save;
}

function MigrateShellCommandToShellCommands(plugin: ShellCommandsPlugin) {
function MigrateShellCommandToPlatforms(plugin: ShellCommandsPlugin) {
let save = false;
for (let shell_command_id in plugin.settings.shell_commands) {
let shell_command_configuration: ShellCommandConfiguration = plugin.settings.shell_commands[shell_command_id];
if (null !== shell_command_configuration.shell_command) {
// The shell command should be migrated.
if (undefined !== shell_command_configuration.shell_commands) {
if (undefined !== shell_command_configuration.platforms) {
console.log("Migration failure for shell command #" + shell_command_id + ": shell_commands exists already.");
} else {
console.log("Migrating shell command #" + shell_command_id + ": shell_command string will be moved to shell_commands.default: " + shell_command_configuration.shell_command);
shell_command_configuration.shell_commands = {
shell_command_configuration.platforms = {
default: shell_command_configuration.shell_command,
};
shell_command_configuration.shell_command = null;
Expand Down
6 changes: 3 additions & 3 deletions src/TShellCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export class TShellCommand {
let operating_system = getOperatingSystem();

// Check if the shell command has defined a specific command for this operating system.
if (undefined === this.configuration.shell_commands[operating_system]) {
if (undefined === this.configuration.platforms[operating_system]) {
// No command is defined specifically for this operating system.
// Return an "OS agnostic" command.
return this.configuration.shell_commands.default;
return this.configuration.platforms.default;
} else {
// The shell command has defined a specific command for this operating system.
return this.configuration.shell_commands[operating_system];
return this.configuration.platforms[operating_system];
}
}
}
13 changes: 9 additions & 4 deletions src/settings/ShellCommandConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {OutputChannel, OutputChannelOrder} from "../output_channels/OutputChannel";
import {IOperatingSystemSpecificString, IOperatingSystemSpecificStringWithDefault} from "./ShellCommandsPluginSettings";
import {IPlatformSpecificString, IPlatformSpecificStringWithDefault} from "./ShellCommandsPluginSettings";

export interface ShellCommandsConfiguration {
[key: string]: ShellCommandConfiguration;
}

export interface ShellCommandConfiguration {
shell_commands: IOperatingSystemSpecificStringWithDefault;
shells: IOperatingSystemSpecificString;
/**
* Contains operating system specific shell commands.
* - key: platform (= OS) name
* - value: shell command
*/
platforms: IPlatformSpecificStringWithDefault;
shells: IPlatformSpecificString;
alias: string;
confirm_execution: boolean;
ignore_error_codes: number[];
Expand All @@ -24,7 +29,7 @@ export interface ShellCommandConfiguration {

export function newShellCommandConfiguration(shell_command: string = ""): ShellCommandConfiguration {
return {
shell_commands: {
platforms: {
default: shell_command,
},
shells: {},
Expand Down
6 changes: 3 additions & 3 deletions src/settings/ShellCommandsPluginSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {ShellCommandsConfiguration} from "./ShellCommandConfiguration";

export interface ShellCommandsPluginSettings {
default_shell: IOperatingSystemSpecificString;
default_shell: IPlatformSpecificString;
working_directory: string;
preview_variables_in_command_palette: boolean;
shell_commands: ShellCommandsConfiguration;
Expand Down Expand Up @@ -45,13 +45,13 @@ export type OperatingSystemName = "darwin" | "linux" | "win32";
*
* @see NodeJS.Platform
*/
export interface IOperatingSystemSpecificString {
export interface IPlatformSpecificString {
/** This is Macintosh */
darwin?: string,
linux?: string,
win32?: string,
}

export interface IOperatingSystemSpecificStringWithDefault extends IOperatingSystemSpecificString{
export interface IPlatformSpecificStringWithDefault extends IPlatformSpecificString{
default?: string,
}

0 comments on commit 997c2be

Please sign in to comment.