-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add upgrade command and update notifier
- Loading branch information
1 parent
13136e8
commit 8bcf024
Showing
8 changed files
with
69 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
import { loadConfig } from "./src/load_config.ts"; | ||
import { VrCommand } from "./src/cli/commands/vr.ts"; | ||
import { version } from "./src/version.ts"; | ||
import { DenoLand, UpdateNotifier } from "./deps.ts"; | ||
import { VR_NAME } from "./src/consts.ts"; | ||
|
||
if (import.meta.main) { | ||
const notifier = new UpdateNotifier({ | ||
name: VR_NAME, | ||
registry: DenoLand, | ||
currentVersion: version, | ||
}); | ||
const checkForUpdates = notifier.checkForUpdates(); | ||
const config = await loadConfig(); | ||
new VrCommand(config) | ||
.parse(Deno.args); | ||
new VrCommand(config).parse(Deno.args); | ||
await checkForUpdates; | ||
notifier.notify("vr upgrade"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Command, DenoLand, semver } from "../../../deps.ts"; | ||
import { log } from "../../logger.ts"; | ||
import { version as currentVersion } from "../../version.ts"; | ||
import { VR_NAME } from "../../consts.ts"; | ||
import { spawn } from "../../util.ts"; | ||
|
||
export class UpgradeCommand extends Command { | ||
constructor() { | ||
super(); | ||
this.description( | ||
"Upgrade Velociraptor to the latest version or to a specific one", | ||
) | ||
.arguments("[version:string]") | ||
.action(async (options, version: string | undefined) => { | ||
let newVersion = version; | ||
if (!newVersion) { | ||
newVersion = await DenoLand.latestVersion(VR_NAME); | ||
} | ||
if (!newVersion) { | ||
log.error("Cannot retrieve the latest version tag"); | ||
return; | ||
} | ||
if (semver.eq(newVersion, currentVersion)) { | ||
log.info("Velociraptor is already up-to-date"); | ||
return; | ||
} | ||
try { | ||
await spawn([ | ||
"deno", | ||
"install", | ||
"--reload", | ||
"-qAfn", | ||
"vr", | ||
`https://deno.land/x/${VR_NAME}@${newVersion}/cli.ts`, | ||
]); | ||
log.info(`✅ Successfully upgraded to ${newVersion}`); | ||
} catch (e) { | ||
console.log(e.message); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export const VR_MARK = "Generated by velociraptor"; | ||
export const VR_NAME = "velociraptor"; | ||
export const VR_MARK = "Generated by Velociraptor"; | ||
export const VR_SHELL = "VR_SHELL"; | ||
export const VR_LOG = "VR_LOG"; | ||
export const VR_HOOKS = "VR_HOOKS"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters