moonrepo / starbase

Framework for building performant command line applications and developer tools.
MIT License
78 stars 6 forks source link

[Bounty] Support shell value quoting #81

Closed milesj closed 3 months ago

milesj commented 3 months ago

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

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'
milesj commented 3 months ago

/bounty $500

algora-pbc[bot] commented 3 months ago

💎 $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
milesj commented 3 months ago

All shells must be implemented to qualify for the bounty!

deepakdinesh1123 commented 3 months ago

/attempt #81

@milesj can I work on this?

urbit-pilled commented 3 months ago

/attempt #81

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

Go for it! Just be sure to rebase after this PR lands: https://github.com/moonrepo/starbase/pull/80

deepakdinesh1123 commented 3 months ago

@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

milesj commented 3 months ago

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

algora-pbc[bot] commented 3 months ago

💡 @varshith257 submitted a pull request that claims the bounty. You can visit your bounty board to reward.

urbit-pilled commented 3 months ago

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

varshith257 commented 3 months ago

@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

milesj commented 3 months ago

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.

algora-pbc[bot] commented 3 months ago

🎉🎈 @varshith257 has been awarded $500! 🎈🎊