aboutsummaryrefslogtreecommitdiff
path: root/pass.c
blob: f7ce19e454a51c9a1ceab62d15b4fc1914c55c8a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "pass_util.h"
#include "util.h"

void print_usage(void);

void print_usage(void)
{
	printf("Usage: pass COMMAND\n\n"

	       "Commands:\n"
	       "  init key-id/fingerprint\n"
	       "	Initialize new password storage\n"
	       "  ls   [ pass-path ]\n"
	       "	List passwords\n"
	       "  rm   pass-name\n"
	       "	Remove password\n"
	       "  add  pass-name\n"
	       "	Add new password\n"
	       "  gen  pass-name\n"
	       "	Generate new password\n"
	       "  cat  pass-name\n"
	       "	Show encrypted password\n"
	       "  help\n"
	       "	Show this help\n");
}

int main(int argc, char *argv[])
{
	int r = 0;
	const char *s = NULL;

	if (!--argc) {
		print_usage();
		exit(EXIT_FAILURE);
	}
	++argv;


	if (!strcmp("help", *argv)) {
		print_usage();
	} else if (!strcmp("init", *argv)) {
		if (!argv[1])
			err_die(1, "invalid usage, try pass help");

		r = pass_init(argv[1]);
	} else if (!strcmp("cat", *argv)) {
		if (!argv[1])
			err_die(1, "invalid usage, try pass help");

		s = pass_cat(argv[1]);
		r = !(s == NULL);
		if (s)
			fputs(s, stdout);
	}

	return r;
}