Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
Add --interactive. Fixes #5.
Browse files Browse the repository at this point in the history
Also fix getListUntrackedFiles, which I somehow broke previously.
  • Loading branch information
mbostock committed Mar 3, 2014
1 parent 0b17632 commit 1fbb65b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
39 changes: 36 additions & 3 deletions bin/gistup
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ var argv = require("optimist").usage("Usage: \033[1mgistup\033[0m [options] -- [
default: "",
describe: "an optional description for your gist"
})
.options("interactive", {
alias: "i",
default: false,
describe: "request confirmation of every file before adding"
})
.options("open", {
default: true,
describe: "open the created gist in your web browser"
Expand All @@ -54,10 +59,11 @@ queue(1)
.defer(gitListUntrackedFiles)
.await(function(error, settings, _, _, files) {
unless(error)
.defer(confirmFiles, files)
.defer(gitAdd, files)
.defer(gitCommit)
.defer(createGist, settings.token)
.await(function(error, _, _, id) {
.await(function(error, _, _, _, id) {
unless(error)
.defer(gitRemoteAdd, id)
.defer(gitPush)
Expand Down Expand Up @@ -148,10 +154,37 @@ function gitRemoteOriginDoesNotExist(callback) {

function gitListUntrackedFiles(callback) {
if (argv._.length) return void callback(null, argv._);
child.exec("git ls-files ls-files --others --exclude-standard --directory -x '*/'", function(error, stdout, stderr) {
child.exec("git ls-files --others --exclude-standard --directory -x '*/'", function(error, stdout, stderr) {
if (!error && stderr) process.stderr.write(stderr), error = new Error("git ls-files failed.");
callback(error, error ? null : stdout.split(os.EOL));
callback(error, error ? null : stdout.trim().split(os.EOL));
});
}

function confirmFiles(files, callback) {
if (!argv.interactive) return void callback(null);
var readin = readline.createInterface({
input: process.stdin,
output: process.stdout
});

var q = queue(1);

files.forEach(function(file, index) {
q.defer(confirmFile, file, index);
});

q.awaitAll(function(error) {
readin.close();
callback(error);
});

function confirmFile(file, index, callback) {
readin.question("add " + file + "? ", function(answer) {
if (/^y|yes$/i.test(answer)) return void callback(null);
if (/^n|no$/i.test(answer)) return files.splice(index, 1), void callback(null);
confirmFile(file, index, callback);
});
}
}

function gitAdd(files, callback) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gistup",
"version": "0.0.6",
"version": "0.0.7",
"description": "Initialize a gist from the command-line.",
"keywords": [
"gist",
Expand Down

0 comments on commit 1fbb65b

Please sign in to comment.