Skip to content

Commit

Permalink
feat: updater with canary releases, specific version installs, change…
Browse files Browse the repository at this point in the history
…log (#236)
  • Loading branch information
JupiterPi authored Dec 22, 2024
2 parents 81ae3e2 + 3c87b2f commit e4baddb
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 60 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ The Filen CLI includes an automatic updater that checks for a new release every
Invoke the CLI with the `--skip-update` flag to skip checking for updates.
(Use the `--force-update` flag to check for updates even if it was recently checked.)

You can always install any version using `filen install <version>`, `filen install latest` or `filen install canary`.

### Canary releases

If you want to be among the first to try out new features and fixes, you can enable canary releases,
which are early releases meant for a subset of users to test before they are declared as stable.
To enable or disable canary releases, invoke the CLI with the command `filen canary`.


# Usage

Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"dedent": "^1.5.3",
"open": "^7.4.2",
"read": "^4.0.0",
"semver": "^7.6.3",
"uuid-by-string": "^4.0.0"
},
"devDependencies": {
Expand Down
21 changes: 20 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,27 @@ export const isDevelopment = args["--dev"] ?? false

// check for updates
if (args["--skip-update"] !== true) {
const updater = new Updater()
if (args["_"][0] === "canary") {
try {
await updater.showCanaryPrompt()
process.exit()
} catch (e) {
errExit("change canary preferences", e)
}
}
if (args["_"][0] === "install") {
try {
const version = args["_"][1]
if (version === undefined) errExit("Need to specify version")
await updater.fetchAndInstallVersion(version)
process.exit()
} catch (e) {
errExit("install version", e)
}
}
try {
await new Updater().checkForUpdates(args["--force-update"] ?? false)
await updater.checkForUpdates(args["--force-update"] ?? false)
} catch (e) {
errExit("check for updates", e)
}
Expand Down
20 changes: 18 additions & 2 deletions src/interface/helpPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class HelpPage {
if (topic === "webdav") return this.webdavHelpPage
if (topic === "s3") return this.s3HelpPage
if (topic === "mount") return this.driveMountingHelpPage
if (topic.startsWith("update")) return this.updatesHelpPage
return undefined
}

Expand Down Expand Up @@ -81,8 +82,6 @@ export class HelpPage {
["--password <password>", ""],
["--two-factor-code <code>, -c <code>", "(optional)"],
["--log-file <file>", "write logs to a file"],
["--skip-update", "skip checking for updates"],
["--force-update", "check for updates even if it was recently checked"],
])}
View the topic pages via \`filen -h <topic>\` for more information:
Expand All @@ -93,6 +92,7 @@ export class HelpPage {
["mount", "Mount a network drive"],
["webdav", "WebDAV mirror server with single user or proxy mode"],
["s3", "S3 mirror server"],
["updates", "Fetching and installing updates"],
])}
Read the full documentation at: https://github.com/FilenCloudDienste/filen-cli${this.versionUrlSegment}#readme
Expand Down Expand Up @@ -203,4 +203,20 @@ export class HelpPage {
Read the full documentation at: https://github.com/FilenCloudDienste/filen-cli${this.versionUrlSegment}#s3-server
`

private readonly updatesHelpPage: string = dedent`
The automatic updater checks for new releases every time the CLI is invoked.
After checking for updates, it will not check again for the next 10 minutes. Use the flags:
--force-update to check for updates even if it was recently checked.
--skip-update to skip checking for updates.
You can always install any version using \`filen install <version>\`, \`filen install latest\` or \`filen install canary\`.
If you want to be among the first to try out new features and fixes, you can enable canary releases,
which are early releases meant for a subset of users to test before they are declared as stable.
To enable or disable canary releases, invoke the CLI with the command \`filen canary\`.
Read the full documentation at: https://github.com/FilenCloudDienste/filen-cli${this.versionUrlSegment}#installation-and-updates
`
}
23 changes: 21 additions & 2 deletions src/interface/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,28 @@ process.stdin.on("keypress", () => {
* @param action The action to include in the prompt (e.g. "delete file.txt"), or undefined for a generic prompt.
*/
export async function promptConfirm(action: string | undefined) {
return promptYesNo(action !== undefined ? `Are you sure you want to ${action}?` : "Are you sure?")
}

/**
* Global confirmation prompting method
* @param question The question to include in the prompt
* @param defaultAnswer The default answer if there's no input
*/
export async function promptYesNo(question: string, defaultAnswer: boolean = false) {
return new Promise<boolean>((resolve) => {
prompt(action !== undefined ? `Are you sure you want to ${action}? [y/N] ` : "Are you sure? [y/N] ").then(result => {
resolve(result.toLowerCase() === "y")
prompt(`${question} ${defaultAnswer ? "[Y/n]" : "[y/N]"} `).then(result => {
const input = result.toLowerCase()
if (input === "n" || input === "no") {
resolve(false)
} else if (input === "y" || input === "yes") {
resolve(true)
} else if (input.trim() === "") {
resolve(defaultAnswer)
} else {
err("Invalid input, please enter 'y' or 'n'!")
promptYesNo(question, defaultAnswer).then(resolve)
}
})
})
}
Loading

0 comments on commit e4baddb

Please sign in to comment.