Reimplemented txt-init in OCaml

Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/kosuzu/trunk@72 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
yakumo.izuru 2024-08-22 15:02:35 +00:00
parent 583f725b21
commit 6e97efbf0c
6 changed files with 23 additions and 49 deletions

1
.gitignore vendored
View File

@ -10,4 +10,3 @@ _build
*.htm
index.html
/.svn
/txt-init

View File

@ -1,44 +0,0 @@
package main
import (
"fmt"
"os"
)
var (
authors string
id string
title string
)
func main() {
fmt.Print("Name of the repository: ")
fmt.Scanln(&title)
fmt.Print("Base32 unique identifier (must be 6 characters long): ")
fmt.Scanln(&id)
fmt.Print("Authors (addresses in the <protocol:name@example.com> format: ")
fmt.Scanln(&authors)
f, err := os.Create("./txt.conf")
if err != nil {
fmt.Println("Error creating txt.conf")
os.Exit(1)
}
defer f.Close()
pwd, err := os.Getwd()
if err != nil {
fmt.Println("Unable to get working directory")
os.Exit(1)
}
f.WriteString("Id: " + fmt.Sprint(id) + "\n")
f.WriteString("Title: " + fmt.Sprint(title) + "\n")
f.WriteString("Authors: " + fmt.Sprint(authors) + "\n")
fmt.Println("All done!")
fmt.Println("Configuration file written to txt.conf")
fmt.Println("Read the documentation in Logarion's repository")
fmt.Printf("%v\n", pwd)
}

3
go.mod
View File

@ -1,3 +0,0 @@
module git.chaotic.ninja/logarion
go 1.21.12

4
init/dune Normal file
View File

@ -0,0 +1,4 @@
(executable
(name init)
(public_name txt_init)
(libraries logarion))

18
init/init.ml Normal file
View File

@ -0,0 +1,18 @@
open Logarion
let init_repo =
print_endline "No txt.conf found";
print_endline "It's required for the repository name and id.";
print_endline "Create one? (y/n)";
match input_line stdin with
|"y"->
let title =
print_endline "Title for repository: ";
input_line stdin in
let authors =
print_endline "Authors (format: name <name@email> <http://website>): ";
input_line stdin in
Logarion.File_store.file "txt.conf"
(Printf.sprintf "Id:%s\nTitle: %s\nAuthors: %s\n" (Logarion.Id.generate ()) title authors);
Logarion.File_store.of_kv_file ()
| _ ->
print_endline "Aborting..."; exit 1

View File

@ -1,6 +1,6 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "1.4.2"
version: "1.4.3"
synopsis: "Texts archival and exchange"
maintainer: ["Izuru Yakumo <yakumo.izuru@chaotic.ninja>"]
authors: ["orbifx <fox@orbitalfox.eu>"]