mirror of
https://github.com/AGWA/git-crypt.git
synced 2025-12-13 08:00:40 -08:00
76 lines
2.2 KiB
C++
76 lines
2.2 KiB
C++
/*
|
|
* Copyright 2012 Andrew Ayer
|
|
*
|
|
* This file is part of git-crypt.
|
|
*
|
|
* git-crypt is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* git-crypt is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with git-crypt. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "commands.hpp"
|
|
#include "util.hpp"
|
|
#include <cstring>
|
|
#include <iostream>
|
|
|
|
static void print_usage (const char* argv0)
|
|
{
|
|
std::clog << "Usage: " << argv0 << " COMMAND [ARGS ...]\n";
|
|
std::clog << "\n";
|
|
std::clog << "Valid commands:\n";
|
|
std::clog << " init KEYFILE - prepare the current git repo to use git-crypt with this key\n";
|
|
std::clog << " keygen KEYFILE - generate a git-crypt key in the given file\n";
|
|
std::clog << "\n";
|
|
std::clog << "Plumbing commands (not to be used directly):\n";
|
|
std::clog << " clean KEYFILE\n";
|
|
std::clog << " smudge KEYFILE\n";
|
|
std::clog << " diff KEYFILE FILE\n";
|
|
}
|
|
|
|
|
|
int main (int argc, const char** argv)
|
|
try {
|
|
// The following two lines are essential for achieving good performance:
|
|
std::ios_base::sync_with_stdio(false);
|
|
std::cin.tie(0);
|
|
|
|
std::cin.exceptions(std::ios_base::badbit);
|
|
std::cout.exceptions(std::ios_base::badbit);
|
|
|
|
if (argc < 3) {
|
|
print_usage(argv[0]);
|
|
return 2;
|
|
}
|
|
|
|
|
|
if (strcmp(argv[1], "init") == 0 && argc == 3) {
|
|
init(argv[0], argv[2]);
|
|
} else if (strcmp(argv[1], "keygen") == 0 && argc == 3) {
|
|
keygen(argv[2]);
|
|
} else if (strcmp(argv[1], "clean") == 0 && argc == 3) {
|
|
clean(argv[2]);
|
|
} else if (strcmp(argv[1], "smudge") == 0 && argc == 3) {
|
|
smudge(argv[2]);
|
|
} else if (strcmp(argv[1], "diff") == 0 && argc == 4) {
|
|
diff(argv[2], argv[3]);
|
|
} else {
|
|
print_usage(argv[0]);
|
|
return 2;
|
|
}
|
|
|
|
return 0;
|
|
} catch (const std::ios_base::failure& e) {
|
|
std::cerr << "git-crypt: I/O error: " << e.what() << std::endl;
|
|
}
|
|
|
|
|