-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(publish): add --access flag to publish command #299
Conversation
0cdf845
to
fb32af4
Compare
src/command/publish.rs
Outdated
match s { | ||
"public" => Ok(Access::Public), | ||
"restricted" => Ok(Access::Restricted), | ||
"private" => Ok(Access::Restricted), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doing something a little unconventional here but i seriously cannot believe that it's "restricted" and not "private" so i kiiiiiinda want to have this in here, but if ya'll object i'm cool with removing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the npm wording is "restricted" but this is creating an alias to that named "private"? I'd prefer just matching what npm does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation here is super funky too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the alias personally. wow cargo fmt what is you doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i talked with nick and am gonna file an issue, it's a bug in cargo fmt, likely from the long string literal
src/command/publish.rs
Outdated
"restricted" => Ok(Access::Restricted), | ||
"private" => Ok(Access::Restricted), | ||
_ => Err(Error::Unsupported { message: format!("{} is not a supported access level. See https://docs.npmjs.com/cli/access for more information on npm package access levels.", s)}), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also really not sure what's up with the formating here, i ran cargo fmt but this is nasty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe if you manually add some \
followed by a newline in the middle of the format string?
i actually just realized that if you pass |
While I personally think that access should default to public, I don't think it is worth creating inconsistencies with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Will be great to have this fixed.
A couple tiny suggestions below, that I think would improve things a bit.
src/command/mod.rs
Outdated
#[structopt(long = "access", short = "a")] | ||
access: Option<Access>, | ||
|
||
/// The access level for the package to be published |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should be on the field above, and the comment for the field above should be here :-p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d'oh. good catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still unaddressed ;)
src/command/publish.rs
Outdated
match s { | ||
"public" => Ok(Access::Public), | ||
"restricted" => Ok(Access::Restricted), | ||
"private" => Ok(Access::Restricted), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the npm wording is "restricted" but this is creating an alias to that named "private"? I'd prefer just matching what npm does.
src/command/publish.rs
Outdated
match s { | ||
"public" => Ok(Access::Public), | ||
"restricted" => Ok(Access::Restricted), | ||
"private" => Ok(Access::Restricted), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation here is super funky too
src/command/publish.rs
Outdated
"restricted" => Ok(Access::Restricted), | ||
"private" => Ok(Access::Restricted), | ||
_ => Err(Error::Unsupported { message: format!("{} is not a supported access level. See https://docs.npmjs.com/cli/access for more information on npm package access levels.", s)}), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe if you manually add some \
followed by a newline in the middle of the format string?
src/command/publish.rs
Outdated
Restricted => "restricted", | ||
}, | ||
None => "", | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about instead of making this stringly typed again, we implement Display
for Access
, implement Default
for Access
, and then right here do
access.unwrap_or_default()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the use of Display
to not have to worry about strings and have it be centralized to one spot so that calls to to_string()
will be consistent as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack. i just reread your message and realized i had missed the "again". anyways, yes, using Display is a good call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the one thing to note is that we can't implement a default- this is because the default changes depending on whether or not the package is scoped, which we don't currently track. i need to think about whether i think it's a good idea to do so, but i had a plan for how to do the default that didn't involve tracking whether it was scoped so i may try that first.
src/npm.rs
Outdated
@@ -18,10 +18,11 @@ pub fn npm_pack(path: &str) -> Result<(), Error> { | |||
} | |||
|
|||
/// Run the `npm publish` command. | |||
pub fn npm_publish(path: &str) -> Result<(), Error> { | |||
pub fn npm_publish(path: &str, access: &str) -> Result<(), Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then this argument would be access: Access
and we know that we can't ever pass a bad access here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pretty much agree with @fitzgen on most of this so if you make the changes he suggested (I personally want the alias) then you can consider this an approval from me
src/command/publish.rs
Outdated
match s { | ||
"public" => Ok(Access::Public), | ||
"restricted" => Ok(Access::Restricted), | ||
"private" => Ok(Access::Restricted), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the alias personally. wow cargo fmt what is you doing.
src/command/publish.rs
Outdated
Restricted => "restricted", | ||
}, | ||
None => "", | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the use of Display
to not have to worry about strings and have it be centralized to one spot so that calls to to_string()
will be consistent as well
failing re doc comments now- gonna fill those out but i think i have one more refactor to make this nicer. it's too bad that the npm access flag doesn't take a default, e.g. |
61080b7
to
b57c947
Compare
0da4fa1
to
3ccc638
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! r=me with that comment below fixed :)
src/command/mod.rs
Outdated
#[structopt(long = "access", short = "a")] | ||
access: Option<Access>, | ||
|
||
/// The access level for the package to be published |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still unaddressed ;)
3ccc638
to
86a4284
Compare
This LGTM great job! Let's get it merged |
fixes #297