Bales
Table of contents
Install
To install:
$ go install github.com/unclassedpenguin/bales@latest
Then, you need to create the config file at ~/.config/bales/config.yaml
As well as create a directory to store the databases. I.e. /home/username/git/databases
Example ~/.config/bales/config.yaml
# Database dir is the directory you want to store your databases in.
# It can be a git repo, but doesn't have to be...
# This directory must be created by the user
DatabaseDir: /home/username/git/databases
# RealDatabase is the legit database
# This will be created if it doesn't exist
RealDatabase: balesDatabase.db
# TestDatabase is a database you can use to test features
# This will be created if it doesn't exist
TestDatabase: balesTestDatabase.db
Don’t forget to edit the DatabaseDir to where you want to store the databases. You just have to create the folder, the databases will be created if they don’t exist.
Troubleshooting
If you get:
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH
You need to install the gcc compiler. For ubuntu, this would be:
$ sudo apt install gcc
Usage
Test Database
If you’d like to try out some commands, without messing around with your working database, use the -t flag. This works for add/remove/list. Just prepend all other flags with -t.
$ bales -t -a -g cows -n 1 # adds entry to test database
$ bales -t -l # lists test database
$ bales -t -d -n 2 # deletes entry in test database with id number 2
Adding Entries
To add a simple entry:
$ bales -a -g cows -n 1
This will add (-a) an entry, with the current date, the group (-g) cows and the number of bales (-n) 1. By default the bale type is round. You can explicitly specify this by using -r flag (although it is unnecessary in this case). If you’d like to add square bales instead, use -s.
# Would add 3 square bales to the group sheep
$ bales -a -g sheep -s -n 3
If you forget to note it down the day you feed, but you want it to have the correct date, you can specify the date using –date.
$ bales -a --date 2022-10-15 -g llamas -s -n 3
List Entries
The most simple way to list is using just -l, which will return all entries for the current month.
$ bales -l
To return the entire database, you must use -all.
$ bales -l -all
When using any other options, all results will be returned. To show only the current month for those cases use -m. (i.e, you want to see how many bales were fed to a specific group in the current month)
$ bales -l -g cows -m
The other options that work with list are:
Option | Description |
-s or -r | List only entries that have square (-s) bales or list only entries that have round (-r) bales |
–date | List an entry for a specific date |
–between | List entries between specific dates. Must be in quotes, and have a space between the dates. Dates are in YYYY-MM-DD format. i.e bales -l -between "2022-06-01 2023-06-01" |
–asc | List entries in ascending order (by date) |
–desc | List entries in descending order (by date) |
–from | takes a date argument. Must be YYYY-MM-DD. Lists all entries from specified date to current date. |
-g | Group to list. Takes a string argument. Lists only the entries where the Animal group matches the string given. As of v0.3.2, you can do multiple groups (as many as you like) by using quotes, and separating them by “ and “. i.e -g "cows and sheep and llamas" |
-m | List current month. |
-year | Year to list. Can be either a single year (i.e. 2022), or a range (i.e. 2019-2021). |
-month | Month to list. Can be either a single month (i.e. 09), or a range (i.e. 09-12). |
-day | Day to list. Can be either a single day (i.e. 09), or a range (i.e. 09-30). |
-sql | Show SQL query that is being sent to database. |
These can be combined in basically anyway, however there are a few that can’t be combined:
- You can’t use -s and -r together. (A bale cannot be square and round at the same time.)
- You can’t use –asc and –desc together. (You can’t order ascending and descending at the same time.)
- You can’t use -m and -month together. (-m sets the month to the current month, So you can’t set the month twice.)
But other than that, you can combine them.
For example, to know how many square bales were fed in month 10:
$ bales -l -month 10 -s
This will list for all years however. So if you need to know for only a specific year, you can do:
$ bales -l -year 2022 -month 10 -s
To list only a specific group:
$ bales -l -g cows
As of v0.3.1, you can use -g "cows and sheep"
which will return any groups matching both names.
As of v0.3.2, you can use as many “ and “ as you want. i.e -g "cows and sheep and llama and horses"
Delete Entries
There are two ways to delete entires from the database. You can delete individual entries by using the ID number, or you can delete entire groups.
If you find that you have mistakenly added a record, or want to remove a single record, first list the database and find the record to be removed. Check what its ID number is, the left most column, and then use that as an identifier to delete the entry.
$ bales -d -n 3
If you want to delete an entire group:
$ bales -d -g cows
You will get a confirmation message asking if you are sure you want to delete all records for the group specified. Answer yes or no. If yes, records will be deleted. If no, the delete will be abandoned and nothing will get changed.