Skip to content

Commit

Permalink
Add 'ls' command
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Carter committed Sep 21, 2020
1 parent ceecaf8 commit a657160
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions ci/release_notes.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Report `crate_version` on stderr in concourse operations
- Add `ls` command - `cepler ls -e <environment>` lists all files tracked by the current config.
20 changes: 20 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ fn app() -> App<'static, 'static> {
(about: "Check wether the environment needs deploying. Exit codes: 0 - needs deploying; 1 - internal error; 2 - nothing to deploy")
(@arg ENVIRONMENT: -e --("environment") env("CEPLER_ENVIRONMENT") +required +takes_value "The cepler environment")
)
(@subcommand ls =>
(about: "List all files relevent to a given environment")
(@arg ENVIRONMENT: -e --("environment") env("CEPLER_ENVIRONMENT") +required +takes_value "The cepler environment")
)
(@subcommand record =>
(about: "Record the state of an environment in the statefile")
(@arg ENVIRONMENT: -e --("environment") env("CEPLER_ENVIRONMENT") +required +takes_value "The cepler environment")
Expand Down Expand Up @@ -79,6 +83,7 @@ pub fn run() -> Result<()> {
}
match matches.subcommand() {
("check", Some(sub_matches)) => check(sub_matches, &matches),
("ls", Some(sub_matches)) => ls(sub_matches, &matches),
("prepare", Some(sub_matches)) => prepare(sub_matches, conf_from_matches(&matches)?),
("record", Some(sub_matches)) => record(sub_matches, conf_from_matches(&matches)?),
("concourse", Some(sub_matches)) => match sub_matches.subcommand() {
Expand Down Expand Up @@ -112,6 +117,21 @@ fn check(matches: &ArgMatches, main_matches: &ArgMatches) -> Result<()> {
}
Ok(())
}

fn ls(matches: &ArgMatches, main_matches: &ArgMatches) -> Result<()> {
let env = matches.value_of("ENVIRONMENT").unwrap();
let config = conf_from_matches(main_matches)?;
let ws = Workspace::new(config.1)?;
let env = config
.0
.environments
.get(env)
.context(format!("Environment '{}' not found in config", env))?;
for path in ws.ls(env)? {
println!("{}", path);
}
Ok(())
}
fn prepare(matches: &ArgMatches, config: (Config, String)) -> Result<()> {
let env = matches.value_of("ENVIRONMENT").unwrap();
let force_clean: bool = matches.is_present("FORCE_CLEAN");
Expand Down
6 changes: 6 additions & 0 deletions src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ impl Workspace {
})
}

pub fn ls(&self, env: &EnvironmentConfig) -> Result<Vec<String>> {
let repo = Repo::open()?;
let new_env_state = self.construct_env_state(&repo, env, false)?;
Ok(new_env_state.files.into_iter().map(|(k, _)| k).collect())
}

pub fn check(&self, env: &EnvironmentConfig) -> Result<Option<(String, Vec<DiffElem>)>> {
let repo = Repo::open()?;
if let Some(previous_env) = env.propagated_from() {
Expand Down

0 comments on commit a657160

Please sign in to comment.