First stab at ipfs init

This commit is contained in:
jmjatlanta 2016-10-26 20:14:07 -05:00
parent fcda3e83ce
commit 689408ffe9
20 changed files with 342 additions and 0 deletions

5
cmd/Makefile Normal file
View file

@ -0,0 +1,5 @@
all:
cd ipfs; make all;
clean:
cd ipfs; make clean;

16
cmd/ipfs/Makefile Normal file
View file

@ -0,0 +1,16 @@
CC = gcc
CFLAGS = -O0
LFLAGS =
DEPS = init.h
OBJS = init.o main.o ../../commands/argument.o
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
ipfs: $(OBJS)
$(CC) -o $@ $^ $(LFLAGS)
all: ipfs
clean:
rm -f *.o

15
cmd/ipfs/init.c Normal file
View file

@ -0,0 +1,15 @@
#include "init.h"
int get_init_command(struct command* cmd) {
// help text
cmd->help_text.tagline = "Initializes IPFS config file.";
cmd->help_text.short_description = "\nInitializes IPFS configuration files and generates a new keypair.\n\nipfs uses a repository in the local file system. By default, the repo is\nlocated at ~/.ipfs. To change the repo location, set the $IPFS_PATH\nenvironment variable.:\n\n export IPFS_PATH=/path/to/ipfsrepo";
// arguments
// initialize an array of arguments with size of 1
struct argument argument;
init_string_argument(&argument, "default-config", 0, 0, "Initialize with the given configuration");
argument.enable_stdin = 1;
struct argument* array[1] = { &argument };
cmd->arguments = array;
return 0;
}

11
cmd/ipfs/init.h Normal file
View file

@ -0,0 +1,11 @@
/**
* Initialize an IPFS repository
*/
#ifndef __CMD_IPFS_INIT_H__
#define __CMD_IPFS_INIT_H__
#include "../../commands/command.h"
int get_init_command(struct command* command);
#endif

BIN
cmd/ipfs/ipfs Executable file

Binary file not shown.

32
cmd/ipfs/main.c Normal file
View file

@ -0,0 +1,32 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void print_help(int longHelp, FILE* outStream) {
}
/**
* command line interface to IPFS.
* Steps:
* 1) parse the command line
* 2) if user requests help, display then exit
* 3) run the command
* 4) output the response
* 5) if anything fails, print the error, maybe with help
*/
int main(int argc, char** argv) {
if (argc == 2) {
if (strncmp(argv[1], "help", 4) == 0) {
print_help(1, stdout);
exit(0);
} else if (strncmp(argv[1], "--version", 9) == 0) {
argv[1] = "version";
}
} // end of help
// parse command line into an invocation
// exit
exit(0);
}