kinda sorta print headers
This commit is contained in:
commit
1d6fb77add
7 changed files with 128 additions and 0 deletions
23
.github/workflows/test.yml
vendored
Normal file
23
.github/workflows/test.yml
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
name: test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: erlef/setup-beam@v1
|
||||
with:
|
||||
otp-version: "26.0.2"
|
||||
gleam-version: "1.0.0"
|
||||
rebar3-version: "3"
|
||||
# elixir-version: "1.15.4"
|
||||
- run: gleam deps download
|
||||
- run: gleam test
|
||||
- run: gleam format --check src test
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
*.beam
|
||||
*.ez
|
||||
/build
|
||||
erl_crash.dump
|
25
README.md
Normal file
25
README.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
# mbox
|
||||
|
||||
[![Package Version](https://img.shields.io/hexpm/v/mbox)](https://hex.pm/packages/mbox)
|
||||
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/mbox/)
|
||||
|
||||
```sh
|
||||
gleam add mbox
|
||||
```
|
||||
```gleam
|
||||
import mbox
|
||||
|
||||
pub fn main() {
|
||||
// TODO: An example of the project in use
|
||||
}
|
||||
```
|
||||
|
||||
Further documentation can be found at <https://hexdocs.pm/mbox>.
|
||||
|
||||
## Development
|
||||
|
||||
```sh
|
||||
gleam run # Run the project
|
||||
gleam test # Run the tests
|
||||
gleam shell # Run an Erlang shell
|
||||
```
|
20
gleam.toml
Normal file
20
gleam.toml
Normal file
|
@ -0,0 +1,20 @@
|
|||
name = "mbox"
|
||||
version = "1.0.0"
|
||||
|
||||
# Fill out these fields if you intend to generate HTML documentation or publish
|
||||
# your project to the Hex package manager.
|
||||
#
|
||||
# description = ""
|
||||
# licences = ["Apache-2.0"]
|
||||
# repository = { type = "github", user = "username", repo = "project" }
|
||||
# links = [{ title = "Website", href = "https://gleam.run" }]
|
||||
#
|
||||
# For a full reference of all the available options, you can have a look at
|
||||
# https://gleam.run/writing-gleam/gleam-toml/.
|
||||
|
||||
[dependencies]
|
||||
gleam_stdlib = "~> 0.36"
|
||||
simplifile = "~> 1.5"
|
||||
|
||||
[dev-dependencies]
|
||||
gleeunit = "~> 1.0"
|
13
manifest.toml
Normal file
13
manifest.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
# This file was generated by Gleam
|
||||
# You typically do not need to edit this file
|
||||
|
||||
packages = [
|
||||
{ name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" },
|
||||
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
|
||||
{ name = "simplifile", version = "1.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "C44DB387524F90DC42142699C78C850003289D32C7C99C7D32873792A299CDF7" },
|
||||
]
|
||||
|
||||
[requirements]
|
||||
gleam_stdlib = { version = "~> 0.36" }
|
||||
gleeunit = { version = "~> 1.0" }
|
||||
simplifile = { version = "~> 1.5"}
|
31
src/mbox.gleam
Normal file
31
src/mbox.gleam
Normal file
|
@ -0,0 +1,31 @@
|
|||
import gleam/io
|
||||
import gleam/dict.{type Dict, new}
|
||||
import simplifile
|
||||
import gleam/result
|
||||
import gleam/string
|
||||
import gleam/list
|
||||
import gleam/pair
|
||||
import gleam/regex
|
||||
import gleam/function
|
||||
|
||||
pub fn main() {
|
||||
io.println("Hello from mbox!")
|
||||
|
||||
get_headers("/home/payas/Downloads/mboxtest")
|
||||
}
|
||||
|
||||
pub fn get_headers(filepath: String) -> Dict(String, String) {
|
||||
let assert Ok(header_pattern) = regex.compile("^[^:]+: ", regex.Options(True, True))
|
||||
|
||||
filepath
|
||||
|> simplifile.read
|
||||
|> result.unwrap(or: "foo")
|
||||
|> string.split_once("\n\n")
|
||||
|> result.unwrap(or: #("", ""))
|
||||
|> pair.first // get only headers
|
||||
|> function.tap(io.println)
|
||||
|> regex.split(header_pattern, _)
|
||||
|> list.map(io.println)
|
||||
|
||||
new()
|
||||
}
|
12
test/mbox_test.gleam
Normal file
12
test/mbox_test.gleam
Normal file
|
@ -0,0 +1,12 @@
|
|||
import gleeunit
|
||||
import gleeunit/should
|
||||
|
||||
pub fn main() {
|
||||
gleeunit.main()
|
||||
}
|
||||
|
||||
// gleeunit test functions end in `_test`
|
||||
pub fn hello_world_test() {
|
||||
1
|
||||
|> should.equal(1)
|
||||
}
|
Loading…
Reference in a new issue