Skip to content

Commit

Permalink
feat: attach mode
Browse files Browse the repository at this point in the history
  • Loading branch information
LumaKernel committed Jan 21, 2021
1 parent 6b139e6 commit 978fd29
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ vfmd restart

Daemon should be running beforehand.

You can also use `vfmd start --attach` or `vfmd restart --attach` not to spawn detached process.

### LSP Settings

Configure following commands to your editors' LSP Client.
Expand Down Expand Up @@ -69,10 +71,10 @@ const processor = unified()
.use(remark2rehype)
.use(html);

processor.process(vfile.readSync(fname), (err, file) => {
processor.process(vfile.readSync(fname), async (err, file) => {
if (err) throw err;
console.error(report(file));
reportToDaemon(file);
await reportToDaemon(file);
file.extname = ".html";
vfile.writeSync(file);
});
Expand Down
49 changes: 32 additions & 17 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,43 @@ import { start } from "../daemon/manage";
// eslint-disable-next-line @typescript-eslint/no-var-requires -- package.json
program.version(require("../../package.json").version, "-v, --version");

program.command("start").action(async () => {
const running = await isRunning();
if (running) {
console.info("already running");
return;
}
const pid = start();
console.info(`Server is started with pid ${pid}`);
process.exit(0);
});
{
const command = program.command("start");
command.option("-a, --attach", "Not to detach").action(async () => {
const { attach } = command.opts();
const running = await isRunning();
if (running) {
console.info("already running");
return;
}
if (attach) {
require("../daemon/server");
} else {
const pid = start();
console.info(`Server is started with pid ${pid}`);
process.exit(0);
}
});
}
program.command("stop").action(async () => {
const stopped = await stop();
console.info(`${stopped ? "stopped" : "already stopped"}`);
process.exit(0);
});
program.command("restart").action(async () => {
await stop();
const pid = start();
console.info(`Server is restarted with pid ${pid}`);
process.exit(0);
});
{
const command = program.command("restart");
command.option("-a, --attach", "Not to detach").action(async () => {
const { attach } = command.opts();
await stop();
if (attach) {
require("../daemon/server");
} else {
const pid = start();
console.info(`Server is restarted with pid ${pid}`);
process.exit(0);
}
});
}
program.command("status").action(async () => {
console.info(`${(await isRunning()) ? "running" : "not running"}`);
process.exit(0);
Expand All @@ -37,7 +53,6 @@ program.command("status").action(async () => {
command
.allowUnknownOption()
.option("--stdio", "Use stdin/stdout to communicate")
.option("-e, --error", "report as errors")
.action(() => {
const options = command.opts();
dump(options);
Expand Down

0 comments on commit 978fd29

Please sign in to comment.