Skip to content

Commit

Permalink
fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
r-zenine committed Dec 11, 2020
1 parent 61d5f04 commit 438ddb8
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ commands:
save_cache_cmd:
steps:
- save_cache:
key: ssam-{{checksum "Cargo.toml"}}
key: sam-{{checksum "Cargo.toml"}}
paths:
- "~/.cargo"
- "./target"

restore_cache_cmd:
steps:
- restore_cache:
key: ssam-{{checksum "Cargo.toml"}}
key: sam-{{checksum "Cargo.toml"}}

prepare_toolchain_linux:
steps:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/target
.packaging/homebrew/ssam.rb
.packaging/homebrew/sam.rb
.packaging/snap/snapcraft.yaml
.packaging/snap/.snapcraft/snapcraft.cfg
6 changes: 3 additions & 3 deletions .packaging/homebrew/homebrew.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/sh
cd `git rev-parse --show-toplevel`
cd .packaging/homebrew
git clone [email protected]:r-zenine/homebrew-ssam.git
cd homebrew-ssam
git clone [email protected]:r-zenine/homebrew-sam.git
cd homebrew-sam
git config --global user.email "[email protected]"
git config --global user.name "Ryad ZENINE"
cp ../ssam.rb Formula/ssam.rb
cp ../sam.rb Formula/sam.rb
git add --all
git commit -a -m"bump version"
git push origin main
14 changes: 14 additions & 0 deletions .packaging/homebrew/ssam.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Documentation: https://docs.brew.sh/Formula-Cookbook
# https://rubydoc.brew.sh/Formula
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
class Sam < Formula
desc "sam lets you difine custom aliases and search them using fuzzy search."
homepage "https://github.com/r-zenine/sam"
url "https://github.com/r-zenine/ssam/releases/download/v0.7.11/sam_macos_x86_64_v0.7.11.tar.gz"
sha256 ""
version "0.7.11"

def install
bin.install "sam"
end
end
2 changes: 1 addition & 1 deletion .packaging/homebrew/ssam.rb.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Documentation: https://docs.brew.sh/Formula-Cookbook
# https://rubydoc.brew.sh/Formula
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
class Ssam < Formula
class Sam < Formula
desc "${PROJECT_DESCRIPTION}"
homepage "${PROJECT_URL}"
url "${PROJECT_URL}/releases/download/v${APP_VERSION}/sam_macos_x86_64_v${APP_VERSION}.tar.gz"
Expand Down
6 changes: 3 additions & 3 deletions .packaging/package_all.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/sh
# change directory to top root of git project.
cd `git rev-parse --show-toplevel`
export PROJECT="ssam"
export PROJECT_URL="https://github.com/r-zenine/ssam"
export PROJECT="sam"
export PROJECT_URL="https://github.com/r-zenine/sam"
export PROJECT_LICENCE="GPL-3.0"
export PROJECT_DESCRIPTION="sam lets you difine custom aliases and search them using fuzzy search."
export APP_VERSION=$(grep Cargo.toml -e "^version = " |sed 's/version \=//' |sed 's/\"//g'|sed 's/ //g')
export ARCHIVE_PATH="./target/x86_64-apple-darwin/release/sam_macos_x86_64_v${APP_VERSION}.tar.gz"
export RELEASE_HASH=$(sha256sum ${ARCHIVE_PATH}|cut -d\ -f1)

envsubst < .packaging/homebrew/ssam.rb.j2 > .packaging/homebrew/ssam.rb
envsubst < .packaging/homebrew/sam.rb.j2 > .packaging/homebrew/sam.rb
envsubst < .packaging/snap/snapcraft.yaml.j2 > .packaging/snap/snapcraft.yaml

./.packaging/homebrew/homebrew.sh && ./.packaging/snap/snap.sh
46 changes: 23 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ description = "sam lets you difine custom aliases and search them using fuzzy se
edition = "2018"
readme = "README.md"
license = "GPL-3.0"
repository = "https://github.com/r-zenine/ssam"
repository = "https://github.com/r-zenine/sam"

[[bin]]
name = "sam"
path = "src/bin/ssam/main.rs"
path = "src/bin/sam/main.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# Metadata for the debian package.
Expand Down
4 changes: 2 additions & 2 deletions src/bin/ssam/config.rs → src/bin/sam/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use ssam::utils::fsutils;
use ssam::utils::fsutils::ErrorsFS;
use sam::utils::fsutils;
use sam::utils::fsutils::ErrorsFS;
use std::path::{Path, PathBuf};
use thiserror::Error;
// Todo
Expand Down
38 changes: 19 additions & 19 deletions src/bin/ssam/main.rs → src/bin/sam/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use ssam::core::aliases::Alias;
use ssam::core::choices::Choice;
use ssam::core::dependencies::Dependencies;
use ssam::core::identifiers::Identifier;
use ssam::core::vars_repository::{ErrorsVarsRepository, VarsRepository};
use ssam::io::readers::{
use sam::core::aliases::Alias;
use sam::core::choices::Choice;
use sam::core::dependencies::Dependencies;
use sam::core::identifiers::Identifier;
use sam::core::vars_repository::{ErrorsVarsRepository, VarsRepository};
use sam::io::readers::{
read_aliases_from_path, read_vars_repository, ErrorsAliasRead, ErrorsVarRead,
};
use ssam::utils::fsutils;
use ssam::utils::fsutils::walk_dir;
use ssam::utils::processes::ShellCommand;
use sam::utils::fsutils;
use sam::utils::fsutils::walk_dir;
use sam::utils::processes::ShellCommand;
use std::collections::HashMap;
use std::process::Command;
use thiserror::Error;
Expand All @@ -21,15 +21,15 @@ use clap::{App, Arg};

const VERSION: &str = env!("CARGO_PKG_VERSION");
const AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
const ABOUT: &str = "ssam lets you difine custom aliases and search them using fuzzy search.";
const ABOUT: &str = "sam lets you difine custom aliases and search them using fuzzy search.";
const ABOUT_SUB_RUN: &str = "show your aliases";
const ABOUT_SUB_ALIAS: &str = "run's a provided alias";
const ABOUT_SUB_BASHRC : &str = "output's a collection of aliases definitions into your bashrc. use 'source `ssa bashrc`' in your bashrc file";

const PROMPT: &str = "Choose an alias to run > ";

fn main() {
let matches = App::new("ssam")
let matches = App::new("sam")
.version(VERSION)
.author(AUTHORS)
.about(ABOUT)
Expand Down Expand Up @@ -59,7 +59,7 @@ fn main() {
(&_, _) => run(dry),
};
match result {
Err(ErrorsSSAM::UI(userinterface::ErrorsUI::SkimAborted)) => {}
Err(Errorssam::UI(userinterface::ErrorsUI::SkimAborted)) => {}
Err(e) => eprintln!(
"{}{}Could not run the program as expected because:{}\n-> {}",
termion::style::Bold,
Expand Down Expand Up @@ -115,7 +115,7 @@ fn run_alias(input: &'_ str, dry: bool) -> Result<i32> {
.aliases
.iter()
.find(|e| e.name() == name && e.namespace() == namespace)
.ok_or(ErrorsSSAM::InvalidAliasSelection)?;
.ok_or(Errorssam::InvalidAliasSelection)?;
execute_alias(&ctx, alias, dry)
}

Expand All @@ -131,7 +131,7 @@ fn execute_alias(ctx: &AppContext, alias: &Alias, dry: bool) -> Result<i32> {
if !dry {
let mut command: Command = ShellCommand::new(final_command).into();
let exit_status = command.status()?;
exit_status.code().ok_or(ErrorsSSAM::ExitCode)
exit_status.code().ok_or(Errorssam::ExitCode)
} else {
Ok(0)
}
Expand All @@ -155,7 +155,7 @@ fn bashrc() -> Result<i32> {
println!("# eval \"$(sam bashrc)\" *");
println!("# *");
println!("# *********************************************");
println!("# START SSAM generated aliases:");
println!("# START sam generated aliases:");
println!("alias am='sam run'");
for alias in aliases {
println!(
Expand All @@ -166,15 +166,15 @@ fn bashrc() -> Result<i32> {
alias.name()
);
}
println!("# STOP SSAM generated aliases:");
println!("# STOP sam generated aliases:");

Ok(0)
}

// Error handling for the sa app.
type Result<T> = std::result::Result<T, ErrorsSSAM>;
type Result<T> = std::result::Result<T, Errorssam>;
#[derive(Debug, Error)]
enum ErrorsSSAM {
enum Errorssam {
#[error("could not return an exit code.")]
ExitCode,
#[error("could not read the configuration file\n-> {0}")]
Expand All @@ -198,7 +198,7 @@ enum ErrorsSSAM {
}

mod logs {
use ssam::core::aliases::Alias;
use sam::core::aliases::Alias;
use std::fmt::Display;
pub fn final_command(alias: &Alias, fc: impl Display) {
println!(
Expand Down
18 changes: 9 additions & 9 deletions src/bin/ssam/userinterface.rs → src/bin/sam/userinterface.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use prettytable::{cell, format, row, Table};
use skim::prelude::*;
use ssam::core::aliases::Alias;
use ssam::core::choices::Choice;
use ssam::core::dependencies::{Dependencies, ErrorsResolver, Resolver};
use ssam::core::identifiers::Identifier;
use ssam::io::readers::read_choices;
use ssam::utils::fsutils::{ErrorsFS, TempFile};
use ssam::utils::processes::ShellCommand;
use sam::core::aliases::Alias;
use sam::core::choices::Choice;
use sam::core::dependencies::{Dependencies, ErrorsResolver, Resolver};
use sam::core::identifiers::Identifier;
use sam::io::readers::read_choices;
use sam::utils::fsutils::{ErrorsFS, TempFile};
use sam::utils::processes::ShellCommand;
use std::cell::RefCell;
use std::collections::HashMap;
use std::fs::File;
Expand Down Expand Up @@ -267,7 +267,7 @@ impl Resolver for UserInterface {

fn resolve_static(
&self,
var: ssam::core::identifiers::Identifier,
var: sam::core::identifiers::Identifier,
cmd: impl Iterator<Item = Choice>,
) -> Result<Choice, ErrorsResolver> {
let mut choices: Vec<Choice> = cmd.collect();
Expand Down Expand Up @@ -311,7 +311,7 @@ where
}

mod logs {
use ssam::core::aliases::Alias;
use sam::core::aliases::Alias;
use std::fmt::Display;
pub fn command(var: impl Display, cmd: impl AsRef<str>) {
println!(
Expand Down
2 changes: 2 additions & 0 deletions src/core/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use crate::core::identifiers::Identifier;
use crate::core::namespaces::Namespace;

pub trait Command: Namespace {
// Returns a string representation of a command
fn command(&self) -> &str;
// Returns the dependencies of an command.
fn dependencies(&self) -> Vec<Identifier> {
Identifier::parse(self.command(), self.namespace())
}
Expand Down
12 changes: 6 additions & 6 deletions src/core/identifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub struct Identifier {
impl Identifier {
/// new creates an new Identifier object and it will sanitize the input.
///```rust
/// use ssam::core::identifiers::Identifier;
/// use ssam::core::namespaces::Namespace;
/// use sam::core::identifiers::Identifier;
/// use sam::core::namespaces::Namespace;
/// let var = Identifier::new("{{ pattern }}");
/// assert_eq!(var.name(), "pattern");
/// let var = Identifier::new("{{ pattern}}");
Expand All @@ -55,8 +55,8 @@ impl Identifier {
}
/// new creates an new Identifier object and it will sanitize the input.
///```rust
/// use ssam::core::identifiers::Identifier;
/// use ssam::core::namespaces::Namespace;
/// use sam::core::identifiers::Identifier;
/// use sam::core::namespaces::Namespace;
/// let var = Identifier::with_namespace("{{ pattern }}", Some("ns"));
/// assert_eq!(var.name(), "pattern");
/// assert_eq!(var.namespace(), Some("ns"));
Expand All @@ -83,8 +83,8 @@ impl Identifier {
/// Dependencies returns the dependencies of this variable if it gets it's
/// choices from a command.
///```rust
/// use ssam::core::identifiers::Identifier;
/// use ssam::core::commands::Command;
/// use sam::core::identifiers::Identifier;
/// use sam::core::commands::Command;
/// let example = Identifier::parse::<&str>("ls -l {{ location }} | grep {{pattern}}", None);
/// assert_eq!(example, vec![Identifier::new("location"), Identifier::new("pattern")]);
///```
Expand Down
6 changes: 3 additions & 3 deletions src/core/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ impl Command for Var {
/// Dependencies returns the dependencies of this variable if it gets it's
/// choices from a command.
///```rust
/// use ssam::core::vars::Var;
/// use ssam::core::identifiers::Identifier;
/// use ssam::core::commands::Command;
/// use sam::core::vars::Var;
/// use sam::core::identifiers::Identifier;
/// use sam::core::commands::Command;
/// let example = Var::from_command("name", "description", "ls -l {{ location }} | grep {{pattern}}");
/// assert_eq!(example.dependencies(), vec![Identifier::new("location"), Identifier::new("pattern")]);
///```
Expand Down
3 changes: 3 additions & 0 deletions ssam.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
}
],
"settings": {
"rust.all_features": true,
"rust-client.updateOnStartup": true,
"rust.racer_completion": false

}
}

0 comments on commit 438ddb8

Please sign in to comment.