Skip to content

Commit

Permalink
[psy] Merge the github.com/psyomn/psy repo here
Browse files Browse the repository at this point in the history
Might save time just shoving everything into this monorepo
  • Loading branch information
psyomn committed Apr 6, 2021
1 parent 3993f21 commit 2992b47
Show file tree
Hide file tree
Showing 26 changed files with 2,120 additions and 40 deletions.
18 changes: 18 additions & 0 deletions common/files.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package common

import (
// TODO: go 1.16 should just use io (see go doc ioutil)
"io/ioutil"
"os"
"path"
)

func FileToBytes(filename string) ([]byte, error) {
Expand All @@ -15,3 +17,19 @@ func FileToBytes(filename string) ([]byte, error) {
bytes, err := ioutil.ReadAll(fs)
return bytes, err
}

func FileExists(filename string) bool {
_, err := os.Stat(filename)
return err != nil
}

// ConfigDir prefers $HOME/.config, regardles of XDG stuff (for now)
func ConfigDir() string {
homeDir := os.Getenv("HOME")

if homeDir == "" {
panic("need home to run")
}

return path.Join(homeDir, ".config", "psy")
}
5 changes: 0 additions & 5 deletions common/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ const (
orgName = "ecophagy"
)

func FileExists(filename string) bool {
_, err := os.Stat(filename)
return err != nil
}

// DownloadIfNotExist will check for a filename, and if it doesn't
// exist, will attempt to download it by a provided url.
func DownloadIfNotExist(filename, url string) error {
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ module github.com/psyomn/ecophagy
go 1.16

require (
github.com/Masterminds/semver v1.5.0
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/mattn/go-sqlite3 v1.14.2
github.com/psyomn/phi v0.0.0-20190317194147-d7548d1a5385
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
16 changes: 14 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-sqlite3 v1.14.2 h1:A2EQLwjYf/hfYaM20FVjs1UewCTTFR7RmjEHkLjldIA=
github.com/mattn/go-sqlite3 v1.14.2/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
github.com/psyomn/phi v0.0.0-20190317194147-d7548d1a5385 h1:P4W+0ttlSTI2Ouhe+B7GGCegN4Qk2Cn9Ad/pzc22Dis=
github.com/psyomn/phi v0.0.0-20190317194147-d7548d1a5385/go.mod h1:hkVuzqg4Hvqa1ERm9btqTEqlQWiGK4vtvVTWbC89iZo=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand All @@ -15,3 +22,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
5 changes: 5 additions & 0 deletions psy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Tools

These are some common tools that I always think about having but never
have. These may be useless to you. These may also reveal terrifying
things about my psyche. Hi.
7 changes: 7 additions & 0 deletions psy/barf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# BARF!

This is a simple implementation that can help one bootstrap different
projects, and get annoying boilerplate out of the way.

I don't like it when things are too tool assisted to get you starting,
but this is half a compromise, I guess.
136 changes: 136 additions & 0 deletions psy/barf/ada.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
Package barf contains code relevant to barfing.
Copyright 2019 Simon Symeonidis (psyomn)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package barf

import (
"bytes"
"fmt"
"os"
"path/filepath"
"text/template"

"github.com/psyomn/ecophagy/psy/common"
)

const (
gpr = `-- Generated Gnat file
-- Example use:
-- gprbuild -P {{.ProjectName}} -Xmode=debug -p
project {{.ProjectName}} is
-- Standard configurations
for Main use ("main.adb");
for Source_Dirs use ("src/**");
for Exec_Dir use "bin/";
-- Ignore git scm stuff
for Ignore_Source_Sub_Dirs use (".git/");
for Object_Dir use "obj/" & external ("mode", "debug");
for Object_Dir use "obj/" & external ("mode", "release");
package Builder is
for Executable ("main.adb") use "{{.ProjectName}}";
end Builder;
-- To invoke either case, you need to set the -X flag at gnatmake in command
-- line. You will also notice the Mode_Type type. This constrains the values
-- of possible valid flags.
type Mode_Type is ("debug", "release");
Mode : Mode_Type := external ("mode", "debug");
package Compiler is
-- Either debug or release mode
case Mode is
when "debug" =>
for Switches ("Ada") use ("-g");
when "release" =>
for Switches ("Ada") use ("-O2");
end case;
end Compiler;
package Binder is end Binder;
package Linker is end Linker;
end {{.ProjectName}};`

mainProgram = `with Ada.Text_IO;
procedure Main is begin
Ada.Text_IO.Put_Line ("hello world");
end Main;
`
)

func ada(args common.RunParams) common.RunReturn {
if len(args) == 0 {
return ErrNeedProjectName
}

type project struct {
ProjectName string
}

t := template.Must(
template.New("ada-project").Parse(gpr),
)
p := project{args[0]}

err := os.MkdirAll(p.ProjectName, 0755)
if err != nil {
return err
}

srcDir := filepath.Join(p.ProjectName, "src")
err = os.MkdirAll(srcDir, 0755)
if err != nil {
return err
}

gprBuff := bytes.NewBuffer([]byte{})
err = t.Execute(gprBuff, p)
if err != nil {
return err
}

gprFilePath := filepath.Join(p.ProjectName, p.ProjectName+".gpr")
file, err := os.Create(gprFilePath)
if err != nil {
return err
}
defer file.Close()

if _, err := file.Write(gprBuff.Bytes()); err != nil {
return err
}

mainFilePath := filepath.Join(srcDir, "main.adb")
file, err = os.Create(mainFilePath)
if err != nil {
return err
}
defer file.Close()

if _, err := file.WriteString(mainProgram); err != nil {
return err
}

fmt.Println("ada project barfed successfully")

return nil
}
Loading

0 comments on commit 2992b47

Please sign in to comment.