Skip to content

Commit

Permalink
Merge pull request #9 from rohaquinlop/issue-4
Browse files Browse the repository at this point in the history
feat(build|docs): #4 update readme
  • Loading branch information
rohaquinlop committed Feb 25, 2024
2 parents 914a6bb + 7119e2b commit c60c92f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
40 changes: 18 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ To run **complexipy** you can use the following command:
<pre lang="shell">
<b>complexipy</b> . # Use complexipy to analyze the current directory and any subdirectories
<b>complexipy</b> path/to/directory # Use complexipy to analyze a specific directory and any subdirectories
<b>complexipy</b> git_repository_url # Use complexipy to analyze a git repository
<b>complexipy</b> path/to/file.py # Use complexipy to analyze a specific file
<b>complexipy</b> path/to/file.py -m 20 # Use the -m option to set the maximum congnitive complexity, default is 15
<b>complexipy</b> path/to/directory -m 0 # Set the maximum cognitive complexity to 0 to disable the exit with error
<b>complexipy</b> path/to/directory -o # Use the -o option to output the results to a XML file, default is False
<b>complexipy</b> path/to/directory -o # Use the -o option to output the results to a CSV file, default is False
</pre>

If the cognitive complexity of a file is greater than the maximum cognitive, then
Expand All @@ -51,38 +52,33 @@ The cognitive complexity of the file is 1, and the output of the command

```bash
$ complexipy path/to/file.py
────────────────── complexipy 1.0.0 🐙 ───────────────────
test_decorator.py
Analysis completed! 🎉
Summary
┏━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Path ┃ File ┃ Complexity ┃
┡━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ ./tests/test_decorat… │ test_decorator.py │ 1 │
└───────────────────────┴───────────────────┴────────────┘
1 files analyzed in 0.0038 seconds
────────────────── complexipy 0.2.0 🐙 ───────────────────
- Finished analysis in test_decorator.py
───────────────── Analysis completed! 🎉 ─────────────────
Results saved to /Users/rhafid/complexipy/complexipy.csv
Summary
┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Path ┃ File ┃ Complexity ┃
┡━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ test_decorator.py │ test_decorator.py │ 1 │
└───────────────────┴───────────────────┴────────────┘
1 files analyzed in 0.0005 seconds
```

If you want to output the results to a XML file, you can use the `-o` option,
If you want to output the results to a CSV file, you can use the `-o` option,
this is really useful if you want to integrate **complexipy** with other tools,
for example, a CI/CD pipeline. You will get the output in the console and will
create a XML file with the results of the analysis.
create a CSV file with the results of the analysis.

```bash
$ complexipy path/to/file.py -o
```

The output will be:

```xml
<?xml version="1.0" ?>
<complexity>
<file>
<name>test_decorator.py</name>
<path>./tests/test_decorator.py</path>
<complexity>1</complexity>
</file>
</complexity>
```csv
Path,File Name,Cognitive Complexity
,test_decorator.py,1
```

## License
Expand Down
21 changes: 19 additions & 2 deletions src/cognitive_complexity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ pub fn main(
) -> PyResult<Vec<FileComplexity>> {
let mut ans: Vec<FileComplexity> = Vec::new();

if is_dir {
println!(
"Analyzing files in {}",
path::Path::new(path)
.canonicalize()
.unwrap()
.to_str()
.unwrap()
);
}

if is_url {
println!("Analyzing files in {}", path);
}

if is_url {
let dir = tempdir()?;
let repo_name = get_repo_name(path);
Expand All @@ -49,7 +64,9 @@ pub fn main(
Err(e) => return Err(e),
}
} else {
match file_cognitive_complexity(path, path, max_complexity) {
let parent_dir = path::Path::new(path).parent().unwrap().to_str().unwrap();

match file_cognitive_complexity(path, parent_dir, max_complexity) {
Ok(file_complexity) => ans.push(file_complexity),
Err(e) => return Err(e),
}
Expand Down Expand Up @@ -111,7 +128,7 @@ pub fn file_cognitive_complexity(
complexity += statement_cognitive_complexity(node.clone(), 0)?;
}

println!("{}", file_name);
println!("- Finished analysis in {}", file_name);

Ok(FileComplexity {
path: relative_path.to_string(),
Expand Down

0 comments on commit c60c92f

Please sign in to comment.