close
close

TOML for lazy developers – DEV Community

TOML for lazy developers – DEV Community

Hello everyone! My name is Peter Wan and I am studying computer science at Seneca Polytechnic.

This week in my Open Source Class, my classmates and I were tasked with adding a new feature to another classmate’s command line tool (CLI). Before you step in What this post was: I’d like to give you some context about the CLI tool I’ve been working on.

The CLI tool I worked on is called Barrierless and was created by my friend Vinh Nhan.

The barrierless The CLI tool uses several major language models (LLMS), such as Groq’s llama3-8b-8192 or Gemini’s gemini-1.5-flash model to take one or more files and convert them to another language.

Let me show you barrierless' basic syntax:



bl-bot (files...) -l  -o (output files...)


Go to full screen mode

Exit full screen mode

Now let me show you an example of how I use it barrierless to convert an English file and a Chinese file into two separate files in French:



bl-bot examples/en-file.txt examples/cn-file.txt -l french -o french-file-1.txt french-file-2.txt


Go to full screen mode

Exit full screen mode

convert files-with-barrier-free

If possible, I wanted to help Vinh add a feature that allows the user to specify some default settings so that his users don’t have to do a lot of typing.

To that end, I made sure that Vinh users could now specify some of their default settings in a custom TOML file called .barrierless.toml. Any user who installs barrierless can choose to create this file in their home directory, if they have some default settings for the barrierless CLI tool. I’ll show you mine:

.barrierless.toml

You will notice that I have specified the default value languagethat is, the language in which the files are converted french.

Now users who are savvy enough with configuration can simply write:



bl-bot (files...) -o (output files...)


Go to full screen mode

Exit full screen mode

instead of:



bl-bot (files...) -l french (output files..)


Go to full screen mode

Exit full screen mode

Fortunately, implementing this feature wasn’t too difficult. It was just a matter of using this TOML parser called ‘toml’ to get the .barrierless.toml file in a user’s home directory.

There were some checks I added to ensure Vinh’s program could run smoothly with or without one .barrierless.toml file, I highlighted the code I added:

https://github.com/vinhyan/barrierless/blob/764bf99c18c1507604baa130dd6a080f2ef2f5c8/src/util.js#L6-L33

The logic of this function ensures that if there is none .barrierless.toml file, then the program doesn’t have to worry about it. If the .barrierless.toml file exists, try extracting the data from it (assuming it is a valid TOML file), if the file exists and it does not a valid TOML file, returns an error message.

This way, existing users of Vinh’s program who do not have a configuration file can use it as before, and other users who want to add a configuration file can get feedback if their file is not configured properly.

That’s about all I want to talk about regarding the features I added, but I also want to discuss my development process for those who are starting to use these git And GitHub to contribute to someone else’s repository.

My process included the following:

  1. Visit Vinh’s barrier-free warehouse and mine own fork of its repository.
  2. Copying the ssh link needed to clone my fork to my local machine:

clone link

  1. Run the following command to clone my fork to my local machine:


git clone [email protected]:peterdanwan/barrierless.git


Go to full screen mode

Exit full screen mode

  1. Add Vinhs upstream repository as an external link to my local repository so I can track any updates Vinh makes to his copy of barrierless:


git remote add upstream https://github.com/vinhyan/barrierless.git


Go to full screen mode

Exit full screen mode

  1. Retrieving all recent updates made to Vinh’s repository so that my local git repository is aware of those changes (this can be run on any branch and should be run often):


git fetch upstream


Go to full screen mode

Exit full screen mode

  1. Merging Vinh’s main upstream branch with mine local main branch (NOTE: I’m on my main branch when I run the command below):


# Merge the changes from upstream/main into my local main branch
git merge upstream/main


Go to full screen mode

Exit full screen mode

  1. Create a topic branch called issue-19, based on the issue number I would be working on.


git checkout -b issue-19


Go to full screen mode

Exit full screen mode

  1. Add files to the staging area and commit my changes (I’ve repeated this step quite a few times)!


git add (files...)

git commit -m "my commit message"


Go to full screen mode

Exit full screen mode

  1. Forward my changes to my forked copy on GitHub (this runs when I have a local change that is not in the forked repository issue-19 branch):


git push origin issue-19


Go to full screen mode

Exit full screen mode

  1. Create a pull request on GitHub asking for my issue-19 branch to the main branch of Vinh.

This Git and GitHub process, as you can see, was quite involvedbut not so bad once you get used to the workflow.

Something to keep in mind is that I have 2 remote control repositories that my local git repository is aware of:

  1. upstream: represents Vinh’s repository
  2. origin: represent my forked one from Vinh’s warehouse

To ensure my pull request runs as smoothly as possible, I continually run the following commands to ensure my commits can stay put on top of any recent changes to Vinh’s headquarters:



# Download the changes from Vinh's GitHub repository into my `upstream` remote
git fetch origin

# Ensure I'm on my local main branch
git checkout main

# Merge Vinh's up-to-date changes from his GitHub's main branch into my local main branch (I am on the main branch when I run the command below):
git merge origin/main

# Ensure I'm back on my feature branch I made earlier
git checkout issue-19

# Have my commits sit on TOP of any recent commits made to my local main branch (which is currently in sync with origin/main):
git rebase main

# ... add files, commit, and push my changes like usual


Go to full screen mode

Exit full screen mode

If you made it this ver, let me just say: thank you! I hope that both the background of Vinh’s repository and the git commands I used also serve some purpose in your development journey.