mirror of
https://github.com/status-im/sourcecred.git
synced 2025-02-07 02:05:10 +00:00
Summary: This ports the OClif version of `sourcecred load` to the sane CLI system. The functionality is similar, but the interface has been changed a bit (mostly simplifications): - The `SOURCECRED_GITHUB_TOKEN` can only be set by an environment variable, not by a command-line argument. This is standard practice because it is more secure: (a) other users on the same system can see the full command line arguments, but not the environment variables, and (b) it’s easier to accidentally leak a command line (e.g., in CI) than a full environment. - The `SOURCECRED_DIRECTORY` can only be set by an environment variable, not by a command-line argument. This is mostly just to simplify the interface, and also because we don’t really have a good name for the argument: we had previously used `-d`, which is unclear, but `--sourcecred-directory` is a bit redundant, while `--directory` is vague and `--sourcecred-directory` is redundant. This is an easy way out, but we can put the flag for this back in if it becomes a problem. - The `--max-old-space-size` argument has been removed in favor of a fixed value. It’s unlikely that users should need to change it. If we’re blowing an 8GB heap, we should try to not do that instead of increasing the heap. - Loading zero repositories, but specifying an output directory, is now valid. This is the right thing to do, but OClif got in our way in the previous implementation. Test Plan: Unit tests added, with full coverage; run `yarn unit`. To try it out, run `yarn backend`, then `node bin/cli.js load --help` to get started. I also manually tested that the following invocations work (i.e., they complete successfully, and `yarn start` shows good data): - `load sourcecred/sourcecred` - `load sourcecred/example-git{,hub} --output sourcecred/examples` These work even when invoked from a different directory. wchargin-branch: cli-load
60 lines
1.3 KiB
JavaScript
60 lines
1.3 KiB
JavaScript
// @flow
|
|
// Implementation of `sourcecred help`.
|
|
|
|
import type {Command} from "./command";
|
|
import dedent from "../util/dedent";
|
|
|
|
import {help as loadHelp} from "./load";
|
|
|
|
const help: Command = async (args, std) => {
|
|
if (args.length === 0) {
|
|
usage(std.out);
|
|
return 0;
|
|
}
|
|
const command = args[0];
|
|
const subHelps: {[string]: Command} = {
|
|
help: metaHelp,
|
|
load: loadHelp,
|
|
};
|
|
if (subHelps[command] !== undefined) {
|
|
return subHelps[command](args.slice(1), std);
|
|
} else {
|
|
usage(std.err);
|
|
return 1;
|
|
}
|
|
};
|
|
|
|
function usage(print: (string) => void): void {
|
|
print(
|
|
dedent`\
|
|
usage: sourcecred COMMAND [ARGS...]
|
|
sourcecred [--version] [--help]
|
|
|
|
Commands:
|
|
load load repository data into SourceCred
|
|
help show this help message
|
|
|
|
Use 'sourcecred help COMMAND' for help about an individual command.
|
|
`.trimRight()
|
|
);
|
|
}
|
|
|
|
const metaHelp: Command = async (args, std) => {
|
|
if (args.length === 0) {
|
|
std.out(
|
|
dedent`\
|
|
usage: sourcecred help [COMMAND]
|
|
|
|
Use 'sourcecred help' for general help and a list of commands.
|
|
Use 'sourcecred help COMMAND' for help about COMMAND.
|
|
`.trimRight()
|
|
);
|
|
return 0;
|
|
} else {
|
|
usage(std.err);
|
|
return 1;
|
|
}
|
|
};
|
|
|
|
export default help;
|