mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-01 22:36:52 +03:00
Merge pull request #857 from AleoHQ/feature/cli-dpii-updates
[CLI, Feature] Adds username substitution to manifest, improves login and error messages
This commit is contained in:
commit
efa3f78362
@ -1,7 +1,15 @@
|
|||||||
# leo login & logout
|
# leo login & logout
|
||||||
|
|
||||||
$LEO new my-app && cd my-app || exit 1
|
|
||||||
$LEO login -u "$ALEO_PM_USERNAME" -p "$ALEO_PM_PASSWORD"
|
$LEO login -u "$ALEO_PM_USERNAME" -p "$ALEO_PM_PASSWORD"
|
||||||
|
$LEO new my-app && cd my-app || exit 1
|
||||||
|
|
||||||
|
cat Leo.toml
|
||||||
|
|
||||||
|
# verify that in Leo.toml there's no line with [AUTHOR];
|
||||||
|
# since CI does not allow showing credentials, we won't see it in the file;
|
||||||
|
# so the only way to test is to make sure that there's just no [AUTHOR] there
|
||||||
|
[[ $(cat Leo.toml | grep "\[AUTHOR\]" | wc -l) -eq 0 ]] || exit 1
|
||||||
|
|
||||||
$LEO add howard/silly-sudoku
|
$LEO add howard/silly-sudoku
|
||||||
$LEO remove silly-sudoku
|
$LEO remove silly-sudoku
|
||||||
$LEO logout
|
$LEO logout
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
$LEO new hello-world
|
$LEO new hello-world
|
||||||
ls -la
|
ls -la
|
||||||
cd hello-world && ls -la
|
cd hello-world && ls -la
|
||||||
|
|
||||||
|
# verify that in Leo.toml there's a placeholder for author
|
||||||
|
# because at the time of calling `leo new` user is not logged in
|
||||||
|
[[ $(cat Leo.toml | grep "\[AUTHOR\]" | wc -l) -eq 1 ]] || exit 1
|
||||||
|
|
||||||
$LEO run
|
$LEO run
|
||||||
|
0
.circleci/r
Normal file
0
.circleci/r
Normal file
20
leo/api.rs
20
leo/api.rs
@ -20,7 +20,7 @@ use reqwest::{
|
|||||||
Method,
|
Method,
|
||||||
StatusCode,
|
StatusCode,
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// Trait describes API Routes and Request bodies, struct which implements
|
/// Trait describes API Routes and Request bodies, struct which implements
|
||||||
/// Route MUST also support Serialize to be usable in Api::run_route(r: Route)
|
/// Route MUST also support Serialize to be usable in Api::run_route(r: Route)
|
||||||
@ -184,12 +184,18 @@ impl Route for Login {
|
|||||||
|
|
||||||
/// Handler for 'my_profile' route. Meant to be used to get profile details but
|
/// Handler for 'my_profile' route. Meant to be used to get profile details but
|
||||||
/// in current application is used to check if user is logged in. Any non-200 response
|
/// in current application is used to check if user is logged in. Any non-200 response
|
||||||
/// is treated as Unauthorized
|
/// is treated as Unauthorized.
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Profile {}
|
pub struct Profile {}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct ProfileResponse {
|
||||||
|
username: String,
|
||||||
|
}
|
||||||
|
|
||||||
impl Route for Profile {
|
impl Route for Profile {
|
||||||
type Output = bool;
|
// Some with Username is success, None is failure.
|
||||||
|
type Output = Option<String>;
|
||||||
|
|
||||||
const AUTH: bool = true;
|
const AUTH: bool = true;
|
||||||
const METHOD: Method = Method::GET;
|
const METHOD: Method = Method::GET;
|
||||||
@ -197,6 +203,12 @@ impl Route for Profile {
|
|||||||
|
|
||||||
fn process(&self, res: Response) -> Result<Self::Output> {
|
fn process(&self, res: Response) -> Result<Self::Output> {
|
||||||
// this may be extended for more precise error handling
|
// this may be extended for more precise error handling
|
||||||
Ok(res.status() == 200)
|
let status = res.status();
|
||||||
|
if status == StatusCode::OK {
|
||||||
|
let body: ProfileResponse = res.json()?;
|
||||||
|
return Ok(Some(body.username));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{commands::Command, context::Context};
|
use crate::{commands::Command, config::*, context::Context};
|
||||||
use leo_package::LeoPackage;
|
use leo_package::LeoPackage;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
@ -43,6 +43,11 @@ impl Command for Init {
|
|||||||
// Derive the package directory path.
|
// Derive the package directory path.
|
||||||
let path = current_dir()?;
|
let path = current_dir()?;
|
||||||
|
|
||||||
|
// Check that the current package directory path exists.
|
||||||
|
if !path.exists() {
|
||||||
|
return Err(anyhow!("Directory does not exist"));
|
||||||
|
}
|
||||||
|
|
||||||
// Check that the given package name is valid.
|
// Check that the given package name is valid.
|
||||||
let package_name = path
|
let package_name = path
|
||||||
.file_stem()
|
.file_stem()
|
||||||
@ -53,12 +58,9 @@ impl Command for Init {
|
|||||||
return Err(anyhow!("Invalid Leo project name"));
|
return Err(anyhow!("Invalid Leo project name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the current package directory path exists.
|
let username = read_username().ok();
|
||||||
if !path.exists() {
|
|
||||||
return Err(anyhow!("Directory does not exist"));
|
|
||||||
}
|
|
||||||
|
|
||||||
LeoPackage::initialize(&package_name, false, &path)?;
|
LeoPackage::initialize(&package_name, false, &path, username)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{commands::Command, context::Context};
|
use crate::{commands::Command, config::*, context::Context};
|
||||||
use leo_package::LeoPackage;
|
use leo_package::LeoPackage;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
@ -49,6 +49,8 @@ impl Command for New {
|
|||||||
return Err(anyhow!("Invalid Leo project name"));
|
return Err(anyhow!("Invalid Leo project name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let username = read_username().ok();
|
||||||
|
|
||||||
// Derive the package directory path.
|
// Derive the package directory path.
|
||||||
let mut path = current_dir()?;
|
let mut path = current_dir()?;
|
||||||
path.push(&package_name);
|
path.push(&package_name);
|
||||||
@ -61,7 +63,7 @@ impl Command for New {
|
|||||||
// Create the package directory
|
// Create the package directory
|
||||||
fs::create_dir_all(&path).map_err(|err| anyhow!("Could not create directory {}", err))?;
|
fs::create_dir_all(&path).map_err(|err| anyhow!("Could not create directory {}", err))?;
|
||||||
|
|
||||||
LeoPackage::initialize(&package_name, false, &path)?;
|
LeoPackage::initialize(&package_name, false, &path, username)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -59,34 +59,15 @@ impl Command for Login {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
|
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
|
||||||
// quick hack to check if user is already logged in. ;)
|
let mut api = context.clone().api;
|
||||||
if context.api.auth_token().is_some() {
|
|
||||||
tracing::info!("You are already logged in");
|
|
||||||
return Ok(context.api.auth_token().unwrap());
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut api = context.api;
|
|
||||||
|
|
||||||
// ...or trying to use arguments to either get token or user-pass
|
// ...or trying to use arguments to either get token or user-pass
|
||||||
let token = match (self.token, self.user, self.pass) {
|
let (token, username) = match (self.token, self.user, self.pass) {
|
||||||
// Login using existing token, use get_profile route for that
|
// Login using username and password if they were passed. Even if token already
|
||||||
(Some(token), _, _) => {
|
// exists login procedure will be done first (we need that for expired credentials).
|
||||||
tracing::info!("Token passed, checking...");
|
|
||||||
|
|
||||||
api.set_auth_token(token.clone());
|
|
||||||
|
|
||||||
let is_ok = api.run_route(ProfileRoute {})?;
|
|
||||||
if !is_ok {
|
|
||||||
return Err(anyhow!("Supplied token is incorrect"));
|
|
||||||
};
|
|
||||||
|
|
||||||
token
|
|
||||||
}
|
|
||||||
|
|
||||||
// Login using username and password
|
|
||||||
(None, Some(email_username), Some(password)) => {
|
(None, Some(email_username), Some(password)) => {
|
||||||
let login = LoginRoute {
|
let login = LoginRoute {
|
||||||
email_username,
|
email_username: email_username.clone(),
|
||||||
password,
|
password,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -98,17 +79,48 @@ impl Command for Login {
|
|||||||
return Err(anyhow!("Unable to get token"));
|
return Err(anyhow!("Unable to get token"));
|
||||||
};
|
};
|
||||||
|
|
||||||
tok_opt.unwrap()
|
(tok_opt.unwrap(), email_username)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Login with token, use get_profile route to verify that.
|
||||||
|
(Some(token), _, _) => {
|
||||||
|
tracing::info!("Token passed, checking...");
|
||||||
|
|
||||||
|
api.set_auth_token(token.clone());
|
||||||
|
|
||||||
|
match api.run_route(ProfileRoute {})? {
|
||||||
|
Some(username) => (token, username),
|
||||||
|
None => return Err(anyhow!("Supplied token is incorrect")),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case token or login/pass were not passed as arguments
|
// In case token or login/pass were not passed as arguments
|
||||||
(_, _, _) => return Err(anyhow!("No credentials provided")),
|
(_, _, _) => {
|
||||||
|
// Check locally stored token if there is.
|
||||||
|
let token = context.api.auth_token();
|
||||||
|
|
||||||
|
match token {
|
||||||
|
Some(token) => {
|
||||||
|
tracing::info!("Found locally stored credentials, verifying...");
|
||||||
|
|
||||||
|
if let Some(username) = api.run_route(ProfileRoute {})? {
|
||||||
|
(token, username)
|
||||||
|
} else {
|
||||||
|
remove_token_and_username()?;
|
||||||
|
return Err(anyhow!(
|
||||||
|
"Stored credentials are incorrect or expired, please login again"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => return Err(anyhow!("No credentials provided")),
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// write token either after logging or if it was passed
|
// write token either after logging or if it was passed
|
||||||
write_token(token.as_str())?;
|
write_token_and_username(token.as_str(), username.as_str())?;
|
||||||
|
|
||||||
tracing::info!("Success! You are now logged in!");
|
tracing::info!("Success! You are logged in!");
|
||||||
|
|
||||||
Ok(token)
|
Ok(token)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{commands::Command, config::remove_token, context::Context};
|
use crate::{commands::Command, config::remove_token_and_username, context::Context};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
@ -41,7 +41,7 @@ impl Command for Logout {
|
|||||||
fn apply(self, _context: Context, _: Self::Input) -> Result<Self::Output> {
|
fn apply(self, _context: Context, _: Self::Input) -> Result<Self::Output> {
|
||||||
// the only error we're interested here is NotFound
|
// the only error we're interested here is NotFound
|
||||||
// however err in this case can also be of kind PermissionDenied or other
|
// however err in this case can also be of kind PermissionDenied or other
|
||||||
if let Err(err) = remove_token() {
|
if let Err(err) = remove_token_and_username() {
|
||||||
match err.kind() {
|
match err.kind() {
|
||||||
ErrorKind::NotFound => {
|
ErrorKind::NotFound => {
|
||||||
tracing::info!("you are not logged in");
|
tracing::info!("you are not logged in");
|
||||||
|
@ -19,7 +19,10 @@ use crate::{
|
|||||||
commands::Command,
|
commands::Command,
|
||||||
context::{Context, PACKAGE_MANAGER_URL},
|
context::{Context, PACKAGE_MANAGER_URL},
|
||||||
};
|
};
|
||||||
use leo_package::{outputs::OutputsDirectory, root::ZipFile};
|
use leo_package::{
|
||||||
|
outputs::OutputsDirectory,
|
||||||
|
root::{ZipFile, AUTHOR_PLACEHOLDER},
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use reqwest::{
|
use reqwest::{
|
||||||
@ -70,11 +73,19 @@ impl Command for Publish {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let package_remote = manifest.get_package_remote().unwrap();
|
let package_remote = manifest.get_package_remote().unwrap();
|
||||||
|
let username = package_remote.clone().author;
|
||||||
|
|
||||||
// Create the output directory
|
// Prevent most common error before accessing API.
|
||||||
|
if username == AUTHOR_PLACEHOLDER {
|
||||||
|
return Err(anyhow!(
|
||||||
|
"Package author is not set. Specify package author in [remote] section of Leo.toml"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the output directory.
|
||||||
OutputsDirectory::create(&path)?;
|
OutputsDirectory::create(&path)?;
|
||||||
|
|
||||||
// Create zip file
|
// Create zip file.
|
||||||
let zip_file = ZipFile::new(&package_name);
|
let zip_file = ZipFile::new(&package_name);
|
||||||
if zip_file.exists_at(&path) {
|
if zip_file.exists_at(&path) {
|
||||||
tracing::debug!("Existing package zip file found. Clearing it to regenerate.");
|
tracing::debug!("Existing package zip file found. Clearing it to regenerate.");
|
||||||
|
@ -32,6 +32,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
pub const LEO_CREDENTIALS_FILE: &str = "credentials";
|
pub const LEO_CREDENTIALS_FILE: &str = "credentials";
|
||||||
pub const LEO_CONFIG_FILE: &str = "config.toml";
|
pub const LEO_CONFIG_FILE: &str = "config.toml";
|
||||||
|
pub const LEO_USERNAME_FILE: &str = "username";
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref LEO_CONFIG_DIRECTORY: PathBuf = {
|
pub static ref LEO_CONFIG_DIRECTORY: PathBuf = {
|
||||||
@ -44,6 +45,11 @@ lazy_static! {
|
|||||||
path.push(LEO_CREDENTIALS_FILE);
|
path.push(LEO_CREDENTIALS_FILE);
|
||||||
path
|
path
|
||||||
};
|
};
|
||||||
|
pub static ref LEO_USERNAME_PATH: PathBuf = {
|
||||||
|
let mut path = LEO_CONFIG_DIRECTORY.to_path_buf();
|
||||||
|
path.push(LEO_USERNAME_FILE);
|
||||||
|
path
|
||||||
|
};
|
||||||
pub static ref LEO_CONFIG_PATH: PathBuf = {
|
pub static ref LEO_CONFIG_PATH: PathBuf = {
|
||||||
let mut path = LEO_CONFIG_DIRECTORY.to_path_buf();
|
let mut path = LEO_CONFIG_DIRECTORY.to_path_buf();
|
||||||
path.push(LEO_CONFIG_FILE);
|
path.push(LEO_CONFIG_FILE);
|
||||||
@ -129,7 +135,7 @@ impl Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_token(token: &str) -> Result<(), io::Error> {
|
pub fn write_token_and_username(token: &str, username: &str) -> Result<(), io::Error> {
|
||||||
let config_dir = LEO_CONFIG_DIRECTORY.clone();
|
let config_dir = LEO_CONFIG_DIRECTORY.clone();
|
||||||
|
|
||||||
// Create Leo config directory if it not exists
|
// Create Leo config directory if it not exists
|
||||||
@ -139,6 +145,10 @@ pub fn write_token(token: &str) -> Result<(), io::Error> {
|
|||||||
|
|
||||||
let mut credentials = File::create(&LEO_CREDENTIALS_PATH.to_path_buf())?;
|
let mut credentials = File::create(&LEO_CREDENTIALS_PATH.to_path_buf())?;
|
||||||
credentials.write_all(&token.as_bytes())?;
|
credentials.write_all(&token.as_bytes())?;
|
||||||
|
|
||||||
|
let mut username_file = File::create(&LEO_USERNAME_PATH.to_path_buf())?;
|
||||||
|
username_file.write_all(&username.as_bytes())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +159,15 @@ pub fn read_token() -> Result<String, io::Error> {
|
|||||||
Ok(buf)
|
Ok(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_token() -> Result<(), io::Error> {
|
pub fn read_username() -> Result<String, io::Error> {
|
||||||
|
let mut username = File::open(&LEO_USERNAME_PATH.to_path_buf())?;
|
||||||
|
let mut buf = String::new();
|
||||||
|
username.read_to_string(&mut buf)?;
|
||||||
|
Ok(buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_token_and_username() -> Result<(), io::Error> {
|
||||||
fs::remove_file(&LEO_CREDENTIALS_PATH.to_path_buf())?;
|
fs::remove_file(&LEO_CREDENTIALS_PATH.to_path_buf())?;
|
||||||
|
fs::remove_file(&LEO_USERNAME_PATH.to_path_buf())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,13 @@ pub struct LeoPackage;
|
|||||||
|
|
||||||
impl LeoPackage {
|
impl LeoPackage {
|
||||||
/// Initializes a Leo package at the given path.
|
/// Initializes a Leo package at the given path.
|
||||||
pub fn initialize(package_name: &str, is_lib: bool, path: &Path) -> Result<(), PackageError> {
|
pub fn initialize(
|
||||||
package::Package::initialize(package_name, is_lib, path)
|
package_name: &str,
|
||||||
|
is_lib: bool,
|
||||||
|
path: &Path,
|
||||||
|
author: Option<String>,
|
||||||
|
) -> Result<(), PackageError> {
|
||||||
|
package::Package::initialize(package_name, is_lib, path, author)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the given Leo package name is valid.
|
/// Returns `true` if the given Leo package name is valid.
|
||||||
|
@ -197,7 +197,12 @@ impl Package {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a package at the given path
|
/// Creates a package at the given path
|
||||||
pub fn initialize(package_name: &str, is_lib: bool, path: &Path) -> Result<(), PackageError> {
|
pub fn initialize(
|
||||||
|
package_name: &str,
|
||||||
|
is_lib: bool,
|
||||||
|
path: &Path,
|
||||||
|
author: Option<String>,
|
||||||
|
) -> Result<(), PackageError> {
|
||||||
// First, verify that this directory is not already initialized as a Leo package.
|
// First, verify that this directory is not already initialized as a Leo package.
|
||||||
{
|
{
|
||||||
if !Self::can_initialize(package_name, is_lib, path) {
|
if !Self::can_initialize(package_name, is_lib, path) {
|
||||||
@ -210,7 +215,7 @@ impl Package {
|
|||||||
// Next, initialize this directory as a Leo package.
|
// Next, initialize this directory as a Leo package.
|
||||||
{
|
{
|
||||||
// Create the manifest file.
|
// Create the manifest file.
|
||||||
Manifest::new(&package_name)?.write_to(&path)?;
|
Manifest::new(&package_name, author)?.write_to(&path)?;
|
||||||
|
|
||||||
// Verify that the .gitignore file does not exist.
|
// Verify that the .gitignore file does not exist.
|
||||||
if !Gitignore::exists_at(&path) {
|
if !Gitignore::exists_at(&path) {
|
||||||
|
@ -26,6 +26,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const MANIFEST_FILENAME: &str = "Leo.toml";
|
pub const MANIFEST_FILENAME: &str = "Leo.toml";
|
||||||
|
pub const AUTHOR_PLACEHOLDER: &str = "[AUTHOR]";
|
||||||
|
|
||||||
#[derive(Clone, Deserialize)]
|
#[derive(Clone, Deserialize)]
|
||||||
pub struct Remote {
|
pub struct Remote {
|
||||||
@ -39,10 +40,10 @@ pub struct Manifest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Manifest {
|
impl Manifest {
|
||||||
pub fn new(package_name: &str) -> Result<Self, ManifestError> {
|
pub fn new(package_name: &str, author: Option<String>) -> Result<Self, ManifestError> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
project: Package::new(package_name)?,
|
project: Package::new(package_name)?,
|
||||||
remote: None,
|
remote: author.map(|author| Remote { author }),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +91,11 @@ impl Manifest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn template(&self) -> String {
|
fn template(&self) -> String {
|
||||||
|
let author = self
|
||||||
|
.remote
|
||||||
|
.clone()
|
||||||
|
.map_or(AUTHOR_PLACEHOLDER.to_string(), |remote| remote.author);
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
r#"[project]
|
r#"[project]
|
||||||
name = "{name}"
|
name = "{name}"
|
||||||
@ -98,9 +104,10 @@ description = "The {name} package"
|
|||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
[remote]
|
[remote]
|
||||||
author = "[AUTHOR]" # Add your Aleo Package Manager username, team's name, or organization's name.
|
author = "{author}" # Add your Aleo Package Manager username, team's name, or organization's name.
|
||||||
"#,
|
"#,
|
||||||
name = self.project.name
|
name = self.project.name,
|
||||||
|
author = author
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,29 @@ fn initialize_valid_package() {
|
|||||||
assert!(Package::can_initialize(TEST_PACKAGE_NAME, false, &test_directory));
|
assert!(Package::can_initialize(TEST_PACKAGE_NAME, false, &test_directory));
|
||||||
|
|
||||||
// Initialize a package at the `test_directory`
|
// Initialize a package at the `test_directory`
|
||||||
assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory).is_ok());
|
assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory, None).is_ok());
|
||||||
|
|
||||||
|
// Ensure a package is initialized at the `test_directory`
|
||||||
|
assert!(Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn initialize_valid_package_with_author() {
|
||||||
|
let test_directory = test_dir();
|
||||||
|
|
||||||
|
// Ensure a package can be initialized at the `test_directory`
|
||||||
|
assert!(Package::can_initialize(TEST_PACKAGE_NAME, false, &test_directory));
|
||||||
|
|
||||||
|
// Initialize a package at the `test_directory`
|
||||||
|
assert!(
|
||||||
|
Package::initialize(
|
||||||
|
TEST_PACKAGE_NAME,
|
||||||
|
false,
|
||||||
|
&test_directory,
|
||||||
|
Some(String::from("test_user"))
|
||||||
|
)
|
||||||
|
.is_ok()
|
||||||
|
);
|
||||||
|
|
||||||
// Ensure a package is initialized at the `test_directory`
|
// Ensure a package is initialized at the `test_directory`
|
||||||
assert!(Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory));
|
assert!(Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory));
|
||||||
@ -52,13 +74,13 @@ fn initialize_fails_with_existing_manifest() {
|
|||||||
assert!(Package::can_initialize(TEST_PACKAGE_NAME, false, &test_directory));
|
assert!(Package::can_initialize(TEST_PACKAGE_NAME, false, &test_directory));
|
||||||
|
|
||||||
// Manually add a manifest file to the `test_directory`
|
// Manually add a manifest file to the `test_directory`
|
||||||
Manifest::new(TEST_PACKAGE_NAME)
|
Manifest::new(TEST_PACKAGE_NAME, None)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.write_to(&test_directory)
|
.write_to(&test_directory)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Attempt to initialize a package at the `test_directory`
|
// Attempt to initialize a package at the `test_directory`
|
||||||
assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory).is_err());
|
assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory, None).is_err());
|
||||||
|
|
||||||
// Ensure package is not initialized at the `test_directory`
|
// Ensure package is not initialized at the `test_directory`
|
||||||
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory));
|
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory));
|
||||||
@ -76,7 +98,7 @@ fn initialize_fails_with_existing_library_file() {
|
|||||||
LibraryFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap();
|
LibraryFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap();
|
||||||
|
|
||||||
// Attempt to initialize a package at the `test_directory`
|
// Attempt to initialize a package at the `test_directory`
|
||||||
assert!(Package::initialize(TEST_PACKAGE_NAME, true, &test_directory).is_err());
|
assert!(Package::initialize(TEST_PACKAGE_NAME, true, &test_directory, None).is_err());
|
||||||
|
|
||||||
// Ensure package is not initialized at the `test_directory`
|
// Ensure package is not initialized at the `test_directory`
|
||||||
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, true, &test_directory));
|
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, true, &test_directory));
|
||||||
@ -94,7 +116,15 @@ fn initialize_fails_with_existing_input_file() {
|
|||||||
InputFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap();
|
InputFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap();
|
||||||
|
|
||||||
// Attempt to initialize a package at the `test_directory`
|
// Attempt to initialize a package at the `test_directory`
|
||||||
assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory).is_err());
|
assert!(
|
||||||
|
Package::initialize(
|
||||||
|
TEST_PACKAGE_NAME,
|
||||||
|
false,
|
||||||
|
&test_directory,
|
||||||
|
Some(String::from("test_user"))
|
||||||
|
)
|
||||||
|
.is_err()
|
||||||
|
);
|
||||||
|
|
||||||
// Ensure package is not initialized at the `test_directory`
|
// Ensure package is not initialized at the `test_directory`
|
||||||
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory));
|
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory));
|
||||||
@ -112,7 +142,7 @@ fn initialize_fails_with_existing_state_file() {
|
|||||||
StateFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap();
|
StateFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap();
|
||||||
|
|
||||||
// Attempt to initialize a package at the `test_directory`
|
// Attempt to initialize a package at the `test_directory`
|
||||||
assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory).is_err());
|
assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory, None).is_err());
|
||||||
|
|
||||||
// Ensure package is not initialized at the `test_directory`
|
// Ensure package is not initialized at the `test_directory`
|
||||||
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory));
|
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory));
|
||||||
@ -130,7 +160,7 @@ fn initialize_fails_with_existing_main_file() {
|
|||||||
MainFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap();
|
MainFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap();
|
||||||
|
|
||||||
// Attempt to initialize a package at the `test_directory`
|
// Attempt to initialize a package at the `test_directory`
|
||||||
assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory).is_err());
|
assert!(Package::initialize(TEST_PACKAGE_NAME, false, &test_directory, None).is_err());
|
||||||
|
|
||||||
// Ensure package is not initialized at the `test_directory`
|
// Ensure package is not initialized at the `test_directory`
|
||||||
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory));
|
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, false, &test_directory));
|
||||||
|
Loading…
Reference in New Issue
Block a user