moonrepo/starbase

[Bounty] Support shell value quoting

milesj opened this issue ยท 13 comments

Our starbase_shell crate supports many CLI shells for formatting environment variables and appending PATH using shell specific syntax. The current implementation "works" but it assumes the formatted values are trivial, and do not include non-trivial values (spaces, required escaping, etc).

We should add a Shell.quote method to each shell, that follows the escaping/quoting rules of that shell, since all shells have their own custom syntax and rules.

pub trait Shell {
    // ...
    fn quote(&self, value: &str) -> String;
}

Furthermore, existing methods should be updated to use the quoting. For example:

// Before
fn format_env_set(&self, key: &str, value: &str) -> String {
    format!(r#"export {key}="{value}";"#)
}

// After
fn format_env_set(&self, key: &str, value: &str) -> String {
    format!("export {}={};", self.quote(key), self.quote(value))
}

Requirements

  • Ideally the quoting is incremental. For example, in Bash, if passed a simple value, it's not quoted.
export KEY=value

But if it contains values that need quoting, then wrap with quotes.

export KEY="value with spaces"

And if it really needs special quoting syntax for complex values, then finally use that.

export KEY=$'value with spaces and escapes, etc'
  • Try to avoid pulling in additional dependencies. At maximum, only 1 dependency is allowed.

/bounty $500

๐Ÿ’Ž $500 bounty โ€ข moonrepo (YC W23)

Steps to solve:

  1. Start working: Comment /attempt #81 with your implementation plan
  2. Submit work: Create a pull request including /claim #81 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to moonrepo/starbase!

Add a bounty โ€ข Share on socials

Attempt Started (GMT+0) Solution
๐ŸŸข @deepakdinesh1123 Jun 28, 2024, 12:29:09 AM WIP
๐Ÿ”ด @urbit-pilled Jun 28, 2024, 1:09:48 AM WIP
๐ŸŸข @varshith257 Jun 30, 2024, 5:54:19 AM #84

All shells must be implemented to qualify for the bounty!

/attempt #81

@milesj can I work on this?

/attempt #81

Algora profile Completed bounties Tech Active attempts Options
@urbit-pilled 6 bounties from 3 projects
Python, JavaScript,
Scala & more
Cancel attempt

Go for it! Just be sure to rebase after this PR lands: #80

@milesj Since the number of formats in which environment variable values can be specified are not too many for a particular shell , I was thinking of using regex to match the pattern in which the value and keys are defined and change the command accordingly, please let me know if this implementation plan seems okay to you and if I need to make any changes

@deepakdinesh1123 You have a quick example of how this would work? Could just be some pseudo code example.

๐Ÿ’ก @varshith257 submitted a pull request that claims the bounty. You can visit your bounty board to reward.

cancelling my attempt because @varshith257's PR seems to have made enough progress with this issue.

@abhishek818 I wanted to touch base regarding the work we're both tackling. I've been heavily invested in resolving the issues and making progress. I'm more interested to complete this work and actively engaged in resolving the issues and making progress. I kindly request that you hold off on proceeding with this particular task until I've had a chance to complete my attempt. If for any reason I decide not to continue, I'll let you know, and you're welcome to take it forward.

I think it results in duplicate of efforts. Hope you consider it @abhishek818
Marking my strong commitment to complete this work with an attempt.

/attempt #81

Thanks everyone for your interest in this bounty. This is my first time using Algolia, so I'm still learning the workflows, so sorry for all the confusion!

With that said, I'll be going with @varshith257's PR, simply because it seems further along, and hits all the requirements. @abhishek818 I'll send you a tip for the work you've done so far, since you spent a good amount of time on it already.

In the near future, I'll have a lot more bounties for starbase, proto, and moon. I just need to find the time to write up all the issues.

๐ŸŽ‰๐ŸŽˆ @varshith257 has been awarded $500! ๐ŸŽˆ๐ŸŽŠ