Skip to content

Commit

Permalink
Define basic command line interface
Browse files Browse the repository at this point in the history
1. Rename the `downloader` module to `actions/download` with the intent
   of placing future implementations of CLI actions under the `actions` top
   levle module.
2. Use `commander` to define basic command line interface:
    * Default _no-name_  command to download all new files from a specified removable drive.
    * `init` command to initialize a global configuration for this tool.
  • Loading branch information
andreiled committed Dec 4, 2023
1 parent b106ab9 commit 19f6c27
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 12 deletions.
15 changes: 13 additions & 2 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@types/chai": "^4.3.9",
"@types/chai-as-promised": "^7.1.8",
"@types/cli-progress": "^3.11.5",
"@types/commander": "^2.12.2",
"@types/jest": "^29.5.8",
"@types/node": "^20.8.10",
"@typescript-eslint/eslint-plugin": "^6.9.1",
Expand All @@ -50,6 +51,7 @@
"**/*": "prettier --write --ignore-unknown"
},
"dependencies": {
"cli-progress": "^3.12.0"
"cli-progress": "^3.12.0",
"commander": "^11.1.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
DirectoryDownloadConfig,
DriveDownloadConfiguration,
readAutoDownloadConfiguration,
} from "../configuration";
import { SequentialNamingScanner } from "../scanner";
import { readDirectoryCursor, saveDirectoryCursor } from "../source-cursor";
} from "../../configuration";
import { SequentialNamingScanner } from "../../scanner";
import { readDirectoryCursor, saveDirectoryCursor } from "../../source-cursor";
import { FileCopier } from "./file-copier";
import { GroupByDatePlacementStrategy, TargetPlacementStrategy } from "./placement-strategy";
import { ProgressTracker } from "./progress";
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions src/actions/download/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Note: consilder all sub-modules to be 'private' to this module and do not re-export any of them here.
import { Downloader } from "./downloader";

export async function downloadAllNewFiles(drivePath: string) {
await new Downloader().downloadAllNewFiles(drivePath);
}
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion src/downloader/index.ts

This file was deleted.

24 changes: 23 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
console.log("Hello world!");
import { program } from "commander";
import { downloadAllNewFiles } from "./actions/download";

program
.command("init")
.description("Initialize a global configuration")
.action(async () => {
// TODO: initialize configuration.
throw new Error("Not implemented yet");
});

program
.description(
`Download all new files from the specified removable drive (e.g. a memory card).
Relies on the global configuration to identify supported directories on the removable drive and to determine where their contents should be saved.`
)
// This removes `[command]` from the default no-name command usage sample to avoid the implication
// that explicit commands (i.e. other than the default no-name command) require the `drive-path` argument.
.usage("<drive-path>")
.argument("<drive-path>", "Removable drive (e.g. memory card) path")
.action(downloadAllNewFiles);

program.parse();
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import { DirectoryDownloadConfig } from "../../src/configuration";
import { findAllSupportedSourceDirs } from "../../src/downloader";
import { DirectoryDownloadConfig } from "../../../src/configuration";
import { findAllSupportedSourceDirs } from "../../../src/actions/download/downloader";

describe("findAllSupportedSourceDirs", () => {
const testConfiguration = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "node:fs/promises";
import * as os from "node:os";
import { FileCopier } from "../../src/downloader/file-copier";
import { FileCopier } from "../../../src/actions/download/file-copier";

jest.mock("node:fs/promises");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stats } from "node:fs";
import * as fs from "node:fs/promises";
import { GroupByDatePlacementStrategy } from "../../src/downloader/placement-strategy";
import { GroupByDatePlacementStrategy } from "../../../src/actions/download/placement-strategy";

jest.mock("node:fs/promises");

Expand Down

0 comments on commit 19f6c27

Please sign in to comment.